2011-04-30 26 views
0
// I created four instance of movieclip on stage and named them t1_mc,t2_mc,t3_mc,t4_mc 

// Then I made and array and loaded them inside the array 

var arr1:Array = new Array(t1_mc, t2_mc, t3_mc, t4_mc); 


var names:String; 


//function made to add event listener to each object 

function addListner():void 

{ 

     for (var i:uint = 0; i < arr1.length; i++) 

        { 

        // Here We are creating four eventlisteners with a function dispNm 

        names = arr1[i].name; 
         names + arr1[i].addEventListener(MouseEvent.CLICK, dispNm); 

        } 

} 

// this will run the function 

addListner(); 

//next I created the dispNm method in this I am trying to get the value "t1" in output by clicking the object named "t1_mc" but I get error!!!!! 

"1119: Access of possibly undefined property target through a reference with static type Class." 

function dispNm(e:MouseEvent):void 

{ 

    if(Event.target.name == 't1_mc') 

    { 

     trace('t1'); 

    } 

} 

我不知道我錯了Actionscript中的事件:如何通過單擊舞臺上的對象來獲取實例名稱值?

請幫助......

回答

0
function dispNm(e:MouseEvent):void 
{ 
    trace(e.target.name); 
} 
+0

非常感謝您UR超級英雄我得到了我是找誰BT u能解釋一點點,實際發生的事情.... !!! ... – Sam 2011-04-30 15:00:08

+1

「事件」是一個類型(一個類名稱),「e」函數參數是您正在處理的MouseEvent的特定實例的引用聽衆,並有你需要的「目標」價值。你唯一一次使用格式ClassName.property的時候是當你訪問類的靜態成員,而「目標」不是。 – 2011-04-30 20:26:43

相關問題