flash制作小球四处弹跳鼠标点击小球就不动的动画
1个回答
展开全部
新建一个flash,第一帧输入如下代码:
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
var s:Sprite = new Sprite();
s.graphics.beginFill(0x00ffff);
s.graphics.drawCircle(0, 0, 30);
s.graphics.endFill();
s.buttonMode = true;
addChild(s);
s.x = (stage.stageWidth - s.width) * Math.random();
s.y = (stage.stageHeight - s.height) * Math.random();
var xs:Number = Math.random() * 4 + 2;
var ys:Number = Math.random() * 4 + 2;
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
s.addEventListener(MouseEvent.CLICK, clickHandler);
function enterFrameHandler(evt:Event):void{
if(s.x + s.width / 2 > stage.stageWidth || s.x < s.width / 2){
xs *= -1;
}
if(s.y + s.height / 2 > stage.stageHeight || s.y < s.height / 2){
ys *= -1;
}
s.x += xs;
s.y += ys;
}
function clickHandler(evt:MouseEvent):void{
if(hasEventListener(Event.ENTER_FRAME)){
removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
else{
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
}
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
var s:Sprite = new Sprite();
s.graphics.beginFill(0x00ffff);
s.graphics.drawCircle(0, 0, 30);
s.graphics.endFill();
s.buttonMode = true;
addChild(s);
s.x = (stage.stageWidth - s.width) * Math.random();
s.y = (stage.stageHeight - s.height) * Math.random();
var xs:Number = Math.random() * 4 + 2;
var ys:Number = Math.random() * 4 + 2;
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
s.addEventListener(MouseEvent.CLICK, clickHandler);
function enterFrameHandler(evt:Event):void{
if(s.x + s.width / 2 > stage.stageWidth || s.x < s.width / 2){
xs *= -1;
}
if(s.y + s.height / 2 > stage.stageHeight || s.y < s.height / 2){
ys *= -1;
}
s.x += xs;
s.y += ys;
}
function clickHandler(evt:MouseEvent):void{
if(hasEventListener(Event.ENTER_FRAME)){
removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
else{
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询