動腦遊戲3
import flash.events.MouseEvent;
import flash.ui.Mouse;
stop();
result_txt.visible=false;
/*
answerA_mc.addEventListener(MouseEvent.CLICK ,pressA);
function pressA(event:MouseEvent) {
answerA_mc.visible=false;
answerB_mc.visible=false;
answerC_mc.visible=false;
//trace("A");
}
*/
answerA_mc.addEventListener(MouseEvent.CLICK, pressA);
function pressA(me:MouseEvent){
result_txt.visible=true;
result_txt.text="答對!";
}
answerB_mc.addEventListener(MouseEvent.CLICK, pressB);
function pressB(me:MouseEvent){
result_txt.text="答錯!";
result_txt.visible=true;
}
answerC_mc.addEventListener(MouseEvent.CLICK, pressC);
function pressC(me:MouseEvent){
result_txt.text="答錯!";
result_txt.visible=true;
}
遙控直升機遊戲
/*right_btn.addEventListener(MouseEvent.MOUSE_OVER, plane_right);
function plane_right(me:MouseEvent){
plane_mc.x += 5 ;
}
left_btn.addEventListener(MouseEvent.CLICK, plane_left);
function plane_left(me:MouseEvent){
plane_mc.x -= 5 ;
}
up_btn.addEventListener(MouseEvent.CLICK, plane_up);
function plane_up(me:MouseEvent){
plane_mc.y -= 5 ;
}
down_btn.addEventListener(MouseEvent.CLICK, plane_down);
function plane_down(me:MouseEvent){
plane_mc.y += 5 ;
}
*/
//定義四個方向速度
var left:Number=0;
var right:Number=0;
var up:Number=0;
var down:Number=0;
//定義速度speed
var speed:Number=10;
up_btn.addEventListener(MouseEvent.MOUSE_OVER, upOver);
function upOver(me:MouseEvent){
up = -speed;
}
up_btn.addEventListener(MouseEvent.MOUSE_OUT, upOUT);
function upOUT(me:MouseEvent){
up = 0;
}
down_btn.addEventListener(MouseEvent.MOUSE_OVER, downOver);
function downOver(me:MouseEvent){
down = speed;
}
down_btn.addEventListener(MouseEvent.MOUSE_OUT, downOUT);
function downOUT(me:MouseEvent){
down = 0;
}
left_btn.addEventListener(MouseEvent.MOUSE_OVER, leftOver);
function leftOver(me:MouseEvent){
left = -speed;
plane_mc.rotation = -10;
}
left_btn.addEventListener(MouseEvent.MOUSE_OUT, leftOUT);
function leftOUT(me:MouseEvent){
left = 0;
plane_mc.rotation = 0;
}
right_btn.addEventListener(MouseEvent.MOUSE_OVER, rightOver);
function rightOver(me:MouseEvent){
right = speed;
plane_mc.rotation = 10;
}
right_btn.addEventListener(MouseEvent.MOUSE_OUT, rightOUT);
function rightOUT(me:MouseEvent){
right = 0;
plane_mc.rotation = 0;
}
//不停更新飛機的四個方向速度
this.addEventListener(Event.ENTER_FRAME, EnterFrame);
function EnterFrame(me:Event){
plane_mc.x += right;
plane_mc.x += left;
plane_mc.y += up;
plane_mc.y += down;
//邊界處理
if (plane_mc.x > stage.stageWidth){
plane_mc.x = 0;
}
if (plane_mc.x < 0){
plane_mc.x = stage.stageWidth;
}
if (plane_mc.y > stage.stageHeight){
plane_mc.y = 0;
}
if (plane_mc.y < 0){
plane_mc.y = stage.stageHeight;
}
}
3.3水果選單
chk_btn.addEventListener(MouseEvent.CLICK, chk);
function chk(me:MouseEvent){
//trace(input_txt.text);
switch (input_txt.text.toLowerCase()) {
case "a":
result_txt.text = "您選Apple";
break;
case "b":
result_txt.text = "您選Banana";
break;
case "c":
result_txt.text = "您選Coconut";
break;
default:
result_txt.text = "您選的不在選單內";
}
}
3.3判斷奇偶數
check_btn.addEventListener(MouseEvent.CLICK , chk);
function chk(me:MouseEvent){
if (int(input_txt.text) % 2 == 0) {
result_txt.text = "偶數";
}else{
result_txt.text = "奇數";
}
}
4.1播放停止
this.stop();
// For Scene
play_btn.addEventListener(MouseEvent.CLICK, man_move);
function man_move(me:MouseEvent){
this.play();
}
stop_btn.addEventListener(MouseEvent.CLICK, man_stop);
function man_stop(me:MouseEvent){
this.stop();
}
// For man_mc
play2_btn.addEventListener(MouseEvent.CLICK, man_move2);
function man_move2(me:MouseEvent){
man_mc.play();
}
stop2_btn.addEventListener(MouseEvent.CLICK, man_stop2);
function man_stop2(me:MouseEvent){
man_mc.stop();
}
4.3地球停止
globe_mc.stop();
globe_mc.addEventListener(MouseEvent.MOUSE_OVER, mouse_in);
function mouse_in(me:MouseEvent){
globe_mc.play();
}
globe_mc.addEventListener(MouseEvent.MOUSE_OUT, mouse_out);
function mouse_out(me:MouseEvent){
globe_mc.stop();
}
4.3利用按鈕切換
stop();
right_btn.addEventListener(MouseEvent.CLICK, nextF);
function nextF(me:MouseEvent){
if(this.currentFrame >= 5){
this.gotoAndStop(1);
}else{
this.nextFrame();
}
}
left_btn.addEventListener(MouseEvent.CLICK, prevF);
function prevF(me:MouseEvent){
if(this.currentFrame <= 1){
this.gotoAndStop(5);
}else{
this.prevFrame();
}
}
4.3影格切換
stop();
a_mc.stop();
next_btn.addEventListener(MouseEvent.CLICK, nextF);
function nextF(me:MouseEvent){
if (a_mc.currentFrame < 5){
a_mc.nextFrame();
} else{
a_mc.gotoAndStop(1);
}
}
prev_btn.addEventListener(MouseEvent.CLICK, prevF);
function prevF(me:MouseEvent){
if(a_mc.currentFrame > 1){
a_mc.prevFrame();
}else{
a_mc.gotoAndStop(5);
}
}
4.4跳場景停止
this.stop();
a_btn.addEventListener(MouseEvent.CLICK, wrong);
function wrong(me:MouseEvent){
this.gotoAndStop(2);
}
b_btn.addEventListener(MouseEvent.CLICK, right);
function right(me:MouseEvent){
this.gotoAndStop(3);
}
4.5切換5照片
//Scene 1
stop();
next_btn.addEventListener(MouseEvent.CLICK, next_scene);
function next_scene(me:MouseEvent){
nextScene();
}
function back_scene(me:MouseEvent){
prevScene();
}
//Scene 2-4
stop();
next_btn.addEventListener(MouseEvent.CLICK, next_scene);
back_btn.addEventListener(MouseEvent.CLICK, back_scene);
//Scene 5
stop();
back_btn.addEventListener(MouseEvent.CLICK, back_scene);
4.5選擇播放
stop(); //影格15及35也須停止
a_btn.addEventListener(MouseEvent.CLICK, playA);
function playA(me:MouseEvent){
this.gotoAndPlay("聖誕老人");
}
b_btn.addEventListener(MouseEvent.CLICK, playB);
function playB(me:MouseEvent){
this.gotoAndPlay("聖誕樹");
}
4.7延遲播放
stop();
var timer=setTimeout(startPlay, 3000);
function startPlay(){
play();
clearTimeout(timer);
}
4.8控制影片播放速度
wheel_mc.stop();
var actMode;
var Rot=0;
var playStep=0;
var Pn=1;
drag_btn.addEventListener(MouseEvent.MOUSE_DOWN, chgYes);
function chgYes(me:MouseEvent){
actMode = "yes";
}
drag_btn.addEventListener(MouseEvent.MOUSE_UP, chgNo);
function chgNo(me:MouseEvent){
actMode = "no";
}
jog_mc.addEventListener(MouseEvent.MOUSE_OVER, chkRot);
function chkRot(me:MouseEvent){
if(actMode == "yes"){
Rot = Math.atan2(jog_mc.mouseX, -jog_mc.mouseY) * 180 / Math.PI;
drag_btn.rotation = Rot;
}
}
this.addEventListener(Event.ENTER_FRAME, cirPlay);
function cirPlay(me:Event){
playStep = Math.floor(Math.abs(Rot)/30);
if (playStep>5){
playStep = 5;
}
Pn = 1;
if (Rot < 0){
Pn = -1;
}
for (var i=1; i<= playStep; i++) {
if (Pn > 0) {
wheel_mc.nextFrame();
if (wheel_mc.currentFrame == wheel_mc.totalFrames){
wheel_mc.gotoAndPlay(1);
}
}else{
wheel_mc.prevFrame();
if (wheel_mc.currentFrame == 1){
wheel_mc.gotoAndPlay(wheel_mc.totalFrames);
}
}
}
fps_txt.text = String(playStep * 12 * Pn);
}
4.9動態控制SWF
fullscreen_btn.addEventListener(MouseEvent.CLICK, fullscreen);
function fullscreen(me:MouseEvent){
fscommand("fullscreen","true");
}
quit_btn.addEventListener(MouseEvent.CLICK, quit);
function quit(me:MouseEvent){
fscommand("quit");
}
menu_btn.addEventListener(MouseEvent.CLICK, menu);
function menu(me:MouseEvent){
//stage.showDefaultContextMenu = false;
stage.showDefaultContextMenu = !stage.showDefaultContextMenu;
}
5.1動態加入
stage.addEventListener(MouseEvent.CLICK, copyMC);
function copyMC(me:MouseEvent) {
var tigerCopy_mc:tiger = new tiger();
stage.addChild(tigerCopy_mc);
tigerCopy_mc.x=this.mouseX;
tigerCopy_mc.y=this.mouseY;
}
5.2動態移除
var addNum:int = 10; //斑馬數量
var basicIndex: Number = this.numChildren -1;
sh_mc.startDrag(true);
//建立舞台上斑馬
for(var i:int=0; i < addNum; i++){
var horseCopy:horse = new horse();
horseCopy.x = 500 * Math.random();
horseCopy.y = 350 * Math.random();
horseCopy.scaleX = horseCopy.scaleY = Math.floor(Math.random() * 10) / 10;
this.addChild(horseCopy);
}
//依滑鼠點選移除斑馬
stage.addEventListener(MouseEvent.CLICK, delMc);
function delMc(me:MouseEvent){
if( basicIndex < this.getChildIndex(me.target)){
this.removeChild(me.target);
}
}
5.3反彈球
var speed:Number = 10;
var speed_x:Number = speed;
var speed_y:Number = speed;
stage.addEventListener(Event.ENTER_FRAME, gogo);
function gogo(me:Event){
with (ball_mc){
x += speed_x;
y += speed_y;
if (x>stage.stageWidth){
x = stage.stageWidth;
speed_x = -speed;
}else if ( x < 0){
x= 0;
speed_x = speed;
}
if (y>stage.stageHeight){
y = stage.stageHeight;
speed_y = -speed;
}else if ( y < 0){
y= 0;
speed_y = speed;
}
}
}
5.5顏色轉換
var color_arr:Array = [0xFF0000, 0xFFFF00, 0x00FFFF, 0x0000FF];
var listNum:int = color_arr.length;
var trans:Transform = new Transform(color_mc);
var my_color:ColorTransform = new ColorTransform();
setInterval(chgcolor, 2000);
function chgcolor(){
var num:int = Math.floor(Math.random() * listNum);
my_color.color = color_arr[num];
trans.colorTransform = my_color;
}
5.6衣服變色
var color_array=[0xFF0000,0x00FF00,0x0000FF,0x00FFFF,0xFFFF00,0xFF00FF,0x9900FF,0xCCCCFF,0xFF9900,0xCC9900,0x3399CC];
a_btn.addEventListener(MouseEvent.CLICK, chgcolor);
b_btn.addEventListener(MouseEvent.CLICK, chgcolor);
c_btn.addEventListener(MouseEvent.CLICK, chgcolor);
d_btn.addEventListener(MouseEvent.CLICK, chgcolor);
e_btn.addEventListener(MouseEvent.CLICK, chgcolor);
f_btn.addEventListener(MouseEvent.CLICK, chgcolor);
g_btn.addEventListener(MouseEvent.CLICK, chgcolor);
h_btn.addEventListener(MouseEvent.CLICK, chgcolor);
i_btn.addEventListener(MouseEvent.CLICK, chgcolor);
j_btn.addEventListener(MouseEvent.CLICK, chgcolor);
k_btn.addEventListener(MouseEvent.CLICK, chgcolor);
function chgcolor(me:MouseEvent){
var my_color:ColorTransform = new ColorTransform();
switch (me.target.name) {
case "a_btn":
my_color.color = color_array[0];
break;
case "b_btn":
my_color.color = color_array[1];
break;
case "c_btn":
my_color.color = color_array[2];
break;
case "d_btn":
my_color.color = color_array[3];
break;
case "e_btn":
my_color.color = color_array[4];
break;
case "f_btn":
my_color.color = color_array[5];
break;
case "g_btn":
my_color.color = color_array[6];
break;
case "h_btn":
my_color.color = color_array[7];
break;
case "i_btn":
my_color.color = color_array[8];
break;
case "j_btn":
my_color.color = color_array[9];
break;
case "k_btn":
my_color.color = color_array[10];
break;
}
cloth_mc.transform.colorTransform = my_color;
}
5.7 廣告位移
stop();
var speed:Number = 0;
stage.addEventListener(Event.ENTER_FRAME, go);
function go(me:Event){
speed = (stage.stageWidth/2 - this.mouseX) / 10;
movie_mc.x += speed;
if(movie_mc.x < 0 || movie_mc.x > 850){
movie_mc.x = 850;
}
}
5.8顫慄的男孩
var strong:Number = 10;
var initX:Number = realboy_mc.x;
var initY:Number = realboy_mc.y;
shakeboy_mc.x = initX;
shakeboy_mc.y = initY;
stage.addEventListener (Event.ENTER_FRAME, goshake);
function goshake(me:Event){
shakeboy_mc.x = initX + shake();
shakeboy_mc.y = initY + shake();
}
function shake(){
return (Math.floor(Math.random()*strong) - strong/2 );
}
5.9 雪花飄
// 場景1的影格1
var snowNum:Number = 30;
for (var i:int=0; i<snowNum; i++){
var mysnow:snow = new snow();
this.addChild(mysnow);
}
// 雪花元件的影格1
this.x = Math.random() * stage.stageWidth;
this.y = Math.random() * stage.stageHeight;
// 雪花元件的影格2
this.y += Math.random() * 5 + 1;
this.x += Math.random() * 5 - 2.5;
// 雪花元件的影格3
if (this.y> stage.stageHeight){
//this.y = 0;
gotoAndPlay(1);
} else{
gotoAndPlay(2);
}
5.10 遮罩開場
basic_mc.visible = false;
mask_mc.visible = false;
mask_mc.stop();
stage.addEventListener(MouseEvent.CLICK, smask);
function smask(me:MouseEvent){
start_txt.visible =false;
basic_mc.visible = true;
mask_mc.visible = true;
basic_mc.mask = mask_mc;
mask_mc.play();
}
沒有留言:
張貼留言