Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 02-06-2005, 03:40 AM   #1
pcarini
Shameless Audiophile
 
pcarini's Avatar
 
Join Date: Aug 2004
Posts: 129
Default Event Listeners not working w/ Nested MovieClips ?

I've been driving myself crazy over this one for a while.

I have one MovieClip nested inside another, and I'm having trouble passing events from the nested to the parent. I'm trying to do this all through scripting, as the MC's are actually custom classes which extend MovieClip.

Here's a sample: - MainClip.as:
ActionScript Code:
class MainClip extends MovieClip {     var nest:nestedClip;     function MainClip()     {         var obj:Object = new Object;         obj.click = function(evt)         {             trace("clicked");         }         nest.addEventListener("click", obj);     } }

And, nestedClip.as
ActionScript Code:
import mx.events.EventDispatcher class nestedClip extends MovieClip {     // Supposedly EventDispatcher adds bodies here     // when initialize is called     function dispatchEvent() {};     function addEventListener() {};     function removeEventListener() {};          function nestedClip()     {         trace(this);         mx.events.EventDispatcher.initialize(this);                 onPress = function()         {             doSomething();         }     }         function doSomething()     {         trace("doSomething called");         dispatchEvent({target:this, type:"click"});     } }

Basically, it'll trace the name of the nested clip, then "doSomething called", and that's all. I can also call doSomething() from within the parent clip, with the same result.

Thanks in advance for any help,
-C
Attached Files
File Type: zip event_thingy.zip (6.0 KB, 179 views)

Last edited by pcarini; 02-06-2005 at 04:06 AM. Reason: I'll attach it, just in case | changed [PHP] tags to [as]
pcarini is offline   Reply With Quote
Old 02-06-2005, 02:14 PM   #2
Xeef
Off-Line
 
Xeef's Avatar
 
Join Date: Aug 2004
Location: Ibiza/Spain language :Hungarian/German/ abit English
Posts: 6,539
Default

hi the problem will by that "MainClip" is initialized at FIRST and then "nestedClip"
and in this order it CAN't work

eg. addEventListener --> and after create "EventDispatcher"

take a look at this mayby it helps a bit :
http://www.actionscript.org/forums/s...d.php3?t=58909
http://www.actionscript.org/forums/s...d.php3?t=63789
__________________

test your self -->http://www.actionscript.org/forums/s...86&postcount=8
Xeef is offline   Reply With Quote
Old 02-06-2005, 10:44 PM   #3
pcarini
Shameless Audiophile
 
pcarini's Avatar
 
Join Date: Aug 2004
Posts: 129
Default

So, an object can only pass events to objects created after itself ? Is there some way to embed one movieclip within another and have the embedded clip initialize first ?

Thanks again,

-C
pcarini is offline   Reply With Quote
Old 02-06-2005, 10:49 PM   #4
pcarini
Shameless Audiophile
 
pcarini's Avatar
 
Join Date: Aug 2004
Posts: 129
Default

I figured it out. Thanks much, Xeef ! I didn't realize from the examples I had seen that I can call initialize() from any function I want, not just the constructor.

Thanks again,

-C
pcarini is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:04 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.