События в Actionscript: как получить значение имени экземпляра, щелкнув объект на сцене? - PullRequest
0 голосов
/ 30 апреля 2011
// 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');

    }

}

я не знаю, где я не прав

Пожалуйста, помогите ......

1 Ответ

0 голосов
/ 30 апреля 2011
function dispNm(e:MouseEvent):void
{
    trace(e.target.name);
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...