//b1,b2為舞臺的二個(gè)元件(在此為圖形、影片剪輯都行)
import flash.display.Sprite
import flash.events.MouseEvent
import flash.display.MovieClip;
b1.addEventListener(MouseEvent.CLICK,px)
b2.addEventListener(MouseEvent.CLICK,px1)
function px(evt:MouseEvent):void{
/*使用getChildAt()返回值是displayObject類(lèi)是抽象類(lèi),一定要實(shí)例化才能使用(也就是批定為一個(gè)具體的實(shí)例下面才能操作)*/
var sp:MovieClip= stage.getChildAt(0) as MovieClip
trace(sp.name) //實(shí)例操作
trace(sp) //實(shí)例操作
trace(stage.numChildren) //實(shí)例操作
/*類(lèi)似:
var yy:Sprite =evt.target as Sprite
yy.x=300 */
}
function px1(evt:MouseEvent):void{
var sp1:Sprite= stage.getChildAt(0) as Sprite
trace(sp1)
trace(sp1.name)
trace(stage.numChildren)
}
聯(lián)系客服