求教as3 用按钮控制不同元件移动问题 5
小弟初学as3不久,遇到一个问题不知该怎么处理,忘大神解救~~~情况是这样的,我在舞台上放置了一个足球一个篮球,还有一个按钮,希望实现这样的效果,当鼠标点击足球或者篮球时...
小弟初学as3不久,遇到一个问题不知该怎么处理,忘大神解救~~~情况是这样的,我在舞台上放置了一个足球一个篮球,还有一个按钮,希望实现这样的效果,当鼠标点击足球或者篮球时,相应的元件旁边生成一个新的元件,然后点击按钮,刚刚生成的这个元件就会往右移动,我写了代码如下,可是现在的问题是,每当我点击按钮,所新生成的所以元件都会动,请问怎么才能实现只让刚刚生成的球移动,而其他的球不动?
lanqiu.addEventListener(MouseEvent.CLICK,onClick1);function onClick1(evt:MouseEvent):void{ var m:M = new M(); m.buttonMode = true; m.height = 50; m.width = 50; m.x = lanqiu.x + 100; m.y = lanqiu.y; m.addEventListener(MouseEvent.MOUSE_DOWN,onDragDown); m.addEventListener(MouseEvent.MOUSE_UP,onDragUp); addChild(m); btn.addEventListener(MouseEvent.MOUSE_DOWN,myouyi); function myouyi(e):void { m.x += 1; }}zuqiu.addEventListener(MouseEvent.CLICK,onClick2);function onClick2(evt:MouseEvent):void{ var z:Z = new Z(); z.buttonMode = true; z.height = 50; z.width = 50; z.x = zuqiu.x + 100; z.y = zuqiu.y; z.addEventListener(MouseEvent.MOUSE_DOWN,onDragDown); z.addEventListener(MouseEvent.MOUSE_UP,onDragUp); addChild(z); btn.addEventListener(MouseEvent.MOUSE_DOWN,zyouyi); function zyouyi(e):void { z.x += 1; }}function onDragDown(evt:MouseEvent):void{ evt.currentTarget.startDrag(true);}function onDragUp(evt:MouseEvent):void{ evt.currentTarget.stopDrag();} 展开
lanqiu.addEventListener(MouseEvent.CLICK,onClick1);function onClick1(evt:MouseEvent):void{ var m:M = new M(); m.buttonMode = true; m.height = 50; m.width = 50; m.x = lanqiu.x + 100; m.y = lanqiu.y; m.addEventListener(MouseEvent.MOUSE_DOWN,onDragDown); m.addEventListener(MouseEvent.MOUSE_UP,onDragUp); addChild(m); btn.addEventListener(MouseEvent.MOUSE_DOWN,myouyi); function myouyi(e):void { m.x += 1; }}zuqiu.addEventListener(MouseEvent.CLICK,onClick2);function onClick2(evt:MouseEvent):void{ var z:Z = new Z(); z.buttonMode = true; z.height = 50; z.width = 50; z.x = zuqiu.x + 100; z.y = zuqiu.y; z.addEventListener(MouseEvent.MOUSE_DOWN,onDragDown); z.addEventListener(MouseEvent.MOUSE_UP,onDragUp); addChild(z); btn.addEventListener(MouseEvent.MOUSE_DOWN,zyouyi); function zyouyi(e):void { z.x += 1; }}function onDragDown(evt:MouseEvent):void{ evt.currentTarget.startDrag(true);}function onDragUp(evt:MouseEvent):void{ evt.currentTarget.stopDrag();} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询