小程序的编写—1
赛马
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.display.Loader;
import flash.net.URLRequest;
public class Main_1 extends MovieClip
{
var sound:Sound=new Sound();
var soundChannel:SoundChannel=new SoundChannel();
var pausePosition:int = soundChannel.position;
public function Main_1()
{
sound.load(new URLRequest("1102.mp3"));
soundChannel = sound.play(pausePosition);
fun();
play_btn.addEventListener(MouseEvent.CLICK,onPlayHandler);
replay_btn.addEventListener(MouseEvent.CLICK,onReplayHandler);
ma_1.gotoAndStop(1);
ma_2.gotoAndStop(1);
ma_3.gotoAndStop(1);
ma_4.gotoAndStop(1);
ma_5.gotoAndStop(1);
ma_1.x = 10;
ma_2.x = 10;
ma_3.x = 10;
ma_4.x = 10;
ma_5.x = 10;
}
public function fun():void
{
ma_1.stop();
ma_2.stop();
ma_3.stop();
ma_4.stop();
ma_5.stop();
ma_1.x = 10;
ma_2.x = 10;
ma_3.x = 10;
ma_4.x = 10;
ma_5.x = 10;
txt.text = "";
}
public function onPlayHandler(e:MouseEvent):void
{
ma_1.addEventListener(Event.ENTER_FRAME,onGo_1);
ma_2.addEventListener(Event.ENTER_FRAME,onGo_2);
ma_3.addEventListener(Event.ENTER_FRAME,onGo_3);
ma_4.addEventListener(Event.ENTER_FRAME,onGo_4);
ma_5.addEventListener(Event.ENTER_FRAME,onGo_5);
}
public function onGo_1(e:Event):void
{
if (ma_1.x >= 520)
{
txt.appendText("1号>");
ma_1.removeEventListener(Event.ENTER_FRAME,onGo_1);
ma_1.gotoAndStop(1);
}
else
{
ma_1.play();
ma_1.x += Math.random() * 10;
}
}
public function onGo_2(e:Event):void
{
if (ma_2.x >= 520)
{
txt.appendText("2号>");
ma_2.removeEventListener(Event.ENTER_FRAME,onGo_2);
ma_2.gotoAndStop(1);
}
else
{
ma_2.play();
ma_2.x += Math.random() * 10;
}
}
public function onGo_3(e:Event):void
{
if (ma_3.x >= 520)
{
txt.appendText("3号>");
ma_3.removeEventListener(Event.ENTER_FRAME,onGo_3);
ma_3.gotoAndStop(1);
}
else
{
ma_3.play();
ma_3.x += Math.random() * 10;
}
}
public function onGo_4(e:Event):void
{
if (ma_4.x >= 520)
{
txt.appendText("4号>");
ma_4.removeEventListener(Event.ENTER_FRAME,onGo_4);
ma_4.gotoAndStop(1);
}
else
{
ma_4.play();
ma_4.x += Math.random() * 10;
}
}
public function onGo_5(e:Event):void
{
if (ma_5.x >= 520)
{
txt.appendText("5号>");
ma_5.removeEventListener(Event.ENTER_FRAME,onGo_5);
ma_5.gotoAndStop(1);
}
else
{
ma_5.play();
ma_5.x += Math.random() * 10;
}
}
public function onReplayHandler(e:Event):void
{
ma_1.x = 10;
ma_2.x = 10;
ma_3.x = 10;
ma_4.x = 10;
ma_5.x = 10;
ma_1.stop();
ma_2.stop();
ma_3.stop();
ma_4.stop();
ma_5.stop();
ma_1.removeEventListener(Event.ENTER_FRAME,onGo_1);
ma_2.removeEventListener(Event.ENTER_FRAME,onGo_2);
ma_3.removeEventListener(Event.ENTER_FRAME,onGo_3);
ma_4.removeEventListener(Event.ENTER_FRAME,onGo_4);
ma_5.removeEventListener(Event.ENTER_FRAME,onGo_5);
txt.text = ""; soundChannel.stop();
}
}
}