Re: [Flashcoders] AS3 - A simple questions

2008-06-05 Thread EECOLOR
I would recommend using event.currentTarget instead of event.target at all
times.

the event.currentTarget property contains a reference to the instance at
which you registered the event listener. event.target refers to the class
that dispatches the event.

In this case there is no difference between .target and .currentTarget, but
in future cases you might encounter problems. The cases where you would use
event.target are so rare that I would urge everyone to allways use
event.currentTarget.


Greetz Erik


On 6/3/08, Rich Shupe [EMAIL PROTECTED] wrote:

 for (var i:int = 0; i  3; i++) {
 var txtFld:TextField = new TextField();
 txtFld.name = TextField + i;
 txtFld.border = true;
 txtFld.x = i*120;
 addChild(txtFld);
 txtFld.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
 }

 function onClick(evt:Event):void {
 trace(Hi I'm, evt.target.name);
 }



 Rich
 http://www.LearningActionScript3.com



 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] AS3 - A simple questions

2008-06-05 Thread Viktor Hesselbom

I use event.target in the current application I'm developing.

It's nice in MouseEvents for determing what is currently under the mouse  
and not what dispatches the event.


On Thu, 05 Jun 2008 14:17:43 +0200, EECOLOR [EMAIL PROTECTED] wrote:

I would recommend using event.currentTarget instead of event.target at  
all

times.

the event.currentTarget property contains a reference to the instance at
which you registered the event listener. event.target refers to the class
that dispatches the event.

In this case there is no difference between .target and .currentTarget,  
but
in future cases you might encounter problems. The cases where you would  
use

event.target are so rare that I would urge everyone to allways use
event.currentTarget.


Greetz Erik


On 6/3/08, Rich Shupe [EMAIL PROTECTED] wrote:


for (var i:int = 0; i  3; i++) {
var txtFld:TextField = new TextField();
txtFld.name = TextField + i;
txtFld.border = true;
txtFld.x = i*120;
addChild(txtFld);
txtFld.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
}

function onClick(evt:Event):void {
trace(Hi I'm, evt.target.name);
}



Rich
http://www.LearningActionScript3.com



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] AS3 - A simple questions

2008-06-03 Thread SJM - Flash
Hi Guys a simple questions for you

Basically I want to produce similar code that creates 3 TextFields and when 
clicked (or focused) they need to say Hi I'm TextField [num], I would like to 
avoid putting the TextFields in MovieClips if possible.

//
// Creates 3 new MovieClips and adds a custom property itm
//
for (var i:Number = 0; i  3; i++)
{
var mc:MovieClip = new MovieClip();
mc.graphics.beginFill(0xFF);
mc.graphics.drawRect(0, 0, 100, 80);
mc.graphics.endFill();
mc.x = 80*i;
mc.y = 60*i;
mc.itm = i;
addChild(mc);
mc.addEventListener(MouseEvent.CLICK, itemClicked);
}


//
// Called when clicked, traces the custom property
//
function itemClicked(ev:Event):void

{
trace(Hi I'm MovieClip  + int(ev.target.itm + 1));
}

Thanks
SJM
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] AS3 - A simple questions

2008-06-03 Thread Rich Shupe
for (var i:int = 0; i  3; i++) {
var txtFld:TextField = new TextField();
txtFld.name = TextField + i;
txtFld.border = true;
txtFld.x = i*120;
addChild(txtFld);
txtFld.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
}

function onClick(evt:Event):void {
trace(Hi I'm, evt.target.name);
}



Rich
http://www.LearningActionScript3.com


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders