Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

target and currentTarget of Actionscript 3.0

This is a discussion on target and currentTarget of Actionscript 3.0 within the Tutorials forums, part of the Flash English category; The Flash CS3 guide talks about it, but I do think that it does not render the concept properly. I ...


Go Back   Forum Flash CS3 Flash CS4 > Flash CS3 Flash CS4 > Flash English > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  3 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 23-09-07, 18:09
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
target and currentTarget of Actionscript 3.0

The Flash CS3 guide talks about it, but I do think that it does not render the concept properly.
I am talking about the properties target and currentTarget of the classes included in the package flash.events ( meaning all the events classes of Actionscript 3.0 ).
It seems that using those two above properties to retrieve the object that has dispatched the event, we find substantial differences that cause troubles to the developer.

Let us see what I am on about?

As an example, we are using a listener to intercept a mouse event on a MovieClip.
I will use the events MOUSE_DOWN and MOUSE_UP of the MouseEvent Class to which I associate a function. Once called, this function will execute startDrag and stopDrag of the MovieClip onto which the events happened.

To realise the above, I will use the property target and currentTarget of the MouseEvent Class to retrieve the clicked MovieClip from the function during the event and so, assign the startDrag.

I create a FLA and save it as ?main.fla?, into which I create a MovieClip in library (shaped as you wish) containing a dynamic text field.
I drag two instances of that MovieClip on stage and I name them ?test_0_mc? and ?test_1_mc?.

Now I write the code:
Code:
test_0_mc.addEventListener(MouseEvent.MOUSE_DOWN,trascina);
test_0_mc.addEventListener(MouseEvent.MOUSE_UP,lascia);

test_1_mc.addEventListener(MouseEvent.MOUSE_DOWN,trascina2);
test_1_mc.addEventListener(MouseEvent.MOUSE_UP,lascia2);

function trascina(m:MouseEvent):void
{
	m.currentTarget.startDrag();
}

function lascia(m:MouseEvent):void
{
	m.currentTarget.stopDrag();
}

function trascina2(m:MouseEvent):void
{
	m.target.startDrag();
}

function lascia2(m:MouseEvent):void
{
	m.target.stopDrag();
}





If we do try to drag the left MovieClip (test_0_mc), we realise that everything goes smooth and Flash from the command m.currentTarget retrace the clicked MovieClip.
Instead, if we do try to drag the right MovieClip, from the error returned by Flash, it seems that it does not find the property startDrag of the TextField Class.

Conclusion, following the logic:
- if we associate the event to an empty MovieClip, best to use the property target
- if we associate the event to a MovieClip containing different objects, best to use the property currentTarget

See you soon!
__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Actionscript 3 Problema con "evento:MouseEvent" e "evento.target.name" Baro Actionscript 3.0 base 2 02-08-08 20:21
Actionscript 3 How to target outside MC renanbarco Actionscript 3.0 newbies 4 08-07-08 10:57
Domanda semplice per Confusione con SCENE e TARGET palooza Flash Italiano 4 27-03-08 11:01
[This, event.target, parent] ibrahack Actionscript 3.0 newbies 7 02-03-08 22:40
Trucco del giorno - target e currentTarget di Actionscript 3.0 Flep Articoli e tutorials 0 21-09-07 08:33


All times are GMT. The time now is 12:39.

Powered by vBulletin version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap