我在场景中有大约1000个对象,每个对象都有特定的符号名称("instance of"),并且实例名称为空。当我点击其中一个对象时,我能以某种方式获得符号名称吗?我可以引用这样的对象,将它们设置为x、y等吗。。。?谢谢
查看它的作用:http://wonderfl.net/c/hJVd
我使用getChildAt
而不是符号名:
package {
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
var container_mc:MovieClip = new MovieClip();
this.addChild(container_mc);
var new_mc:MovieClip;
for(var i:int=0;i<50;i++){
new_mc = new MovieClip();
new_mc.graphics.beginFill(Math.random()*0xFF0000,08);
new_mc.x = Math.random()*stage.stageWidth;
new_mc.y = Math.random()*stage.stageHeight;
new_mc.graphics.drawCircle(0,0,20);
new_mc.graphics.endFill();
//new_mc.addEventListener(MouseEvent.MOUSE_DOWN,pressMc);//you can add event here or[2*]
container_mc.addChild(new_mc);
}
//[2*]if you have already childs inside parent MovieClip:
var totalChilds:int = container_mc.getChildNums;
for(var c:int=0;c<totalChilds;c++){
var mychild_mc:* = container_mc.getChildAt(c);
mychild_mc.addEventListener(MouseEvent.MOUSE_DOWN,pressMc);
}
function pressMc(e:MouseEvent):void{
trace(e.target);
}
}
}
}
as2/as3问题是相关的。
这取决于你所说的点击是什么意思。如果你正在运行一个flash应用程序,是的,你可以注册一个事件监听器来获取你点击一个符号实例时的位置。当您需要从时间线上的父对象访问符号时,符号需要一个名称。
您可以使用getChildAt(index)方法访问MovieClip的子级,并使用numChildren字段i AS3:获取子级数量
http://livedocs.adobe.com/flash/9.0_fr/ActionScriptLangRefV3/flash/display/MovieClip.html#methodSummary
是的,如果您使用的是AS3,请按照以下步骤操作:
循环浏览每个对象并添加一个点击事件:
myObject1.addEventListener(MouseEvent.Click, onClick);
创建处理正在侦听的事件的方法:
function onClick(e:MouseEvent) {
var myObject:Sprite = e.currentTarget as Sprite;
myObject.x = 10; // etc
}
这将允许您在单击后获取对象的引用并对其进行操作。