Home Tutorials Forums Articles Blogs Movies Library Employment Press

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

Reply
 
Thread Tools Rate Thread Display Modes
Old 12-12-2009, 01:04 AM   #1
loganbest
Registered User
 
Join Date: Oct 2006
Posts: 41
Default Dispatching Events not working

I have an event dispatcher in an irrelevant part of the fla and it works great, but when I go to set it up in this part of the fla it doesn't work. In the irrelevant part it dispatches from an MC to the main timeline which has a listener on it in the first frame then it does it's thing.

maintimeline with listener -> MC with dispatcher

In this part I have the dispatcher dispatching an event from inside an MC to a nested MC.

maintimeline -> MC with dispatcher -> MC with listener

Dispatcher:
ActionScript Code:
stop(); import flash.events.EventDispatcher; import flash.events.Event; inperformanceBtn.addEventListener(MouseEvent.CLICK,inperf); function inperf(evt:MouseEvent):void {         dispatchEvent(new Event("inperfplay", true));     trace("perf clicked"); } pieBtn.addEventListener(MouseEvent.CLICK,inpie); function inpie(evt:MouseEvent):void {         dispatchEvent(new Event("inpie", true));     trace("pie clicked"); }

Listener:
ActionScript Code:
stop(); addEventListener("closebtn", closebtn); addEventListener("inperfplay", inperfPlay); addEventListener("inpie", inpie);// listen for the custom event dispatched by button function inperfPlay(e:Event):void {     trace("perf rec");     popupMC.gotoAndStop(1);     gotoAndPlay("popIn");     } function inpie(e:Event):void {     popupMC.gotoAndStop(1);     gotoAndPlay("popIn"); } function closebtn(e:Event):void {     gotoAndPlay("popOut"); }

It's setup pretty much the exact same way as the other one. I'm lost.
loganbest is offline   Reply With Quote
Old 12-12-2009, 04:39 AM   #2
Mazoonist
Site Contributor
 
Mazoonist's Avatar
 
Join Date: Jun 2006
Posts: 3,160
Send a message via AIM to Mazoonist
Default

In the first block of code, your buttons are not dispatching those events, it is the enclosing scope that is dispatching the events (the MC that contains these buttons), although this event dispatch is being triggered by clicks on the buttons.

So for a nested movie clip within this one to register for those dispatched events, it would have to use parent, for example in your case:

this.parent.addEventListener("inpie", inpie);

You have to always add event listeners to the same object that is dispatching them (there is one exception but I probably shouldn't confuse you with bubbling events right now).

The events are being dispatched by the nested movie clip's parent, so that is the object you must add the listeners to.
__________________
My Tutorials * My Website

Last edited by Mazoonist; 12-12-2009 at 04:41 AM.
Mazoonist is offline   Reply With Quote
Old 12-12-2009, 11:57 AM   #3
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,679
Send a message via Skype™ to henke37
Default

You got lucky, the event propagated thrught the displaylist. But that does not happen for events targeted at parent objects.
henke37 is offline   Reply With Quote
Old 12-12-2009, 03:33 PM   #4
Mazoonist
Site Contributor
 
Mazoonist's Avatar
 
Join Date: Jun 2006
Posts: 3,160
Send a message via AIM to Mazoonist
Default

henke37,

I don't know if that reply was intended for me or the other person. But I was just trying to explain how dispatching events work. Sometimes I answer people in the context of what they have already set up, even if I don't agree with it, or it's not the way I would do it. Understand?
__________________
My Tutorials * My Website
Mazoonist is offline   Reply With Quote
Old 12-12-2009, 04:39 PM   #5
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,679
Send a message via Skype™ to henke37
Default

It was for loganbest.
henke37 is offline   Reply With Quote
Old 12-12-2009, 05:15 PM   #6
loganbest
Registered User
 
Join Date: Oct 2006
Posts: 41
Default

well now it gets to the other function correctly but now its not registering the MC label that I manually typed it, not dynamically.

ActionScript Code:
perf rec TypeError: Error #1009: Cannot access a property or method of a null object reference.     at site_fla::popupContainer_6/inperfPlay()     at flash.events::EventDispatcher/dispatchEventFunction()     at flash.events::EventDispatcher/dispatchEvent()     at site_fla::contentMC_5/inperf() perf clicked
loganbest is offline   Reply With Quote
Old 12-12-2009, 06:16 PM   #7
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,679
Send a message via Skype™ to henke37
Default

Oh, it found the property alright. The property was just null. The object did not exist at that point in time.
henke37 is offline   Reply With Quote
Old 12-12-2009, 06:18 PM   #8
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,679
Send a message via Skype™ to henke37
Default

The property was found, but it's value at that point in time was null. This is due to the instance not existing at that point in time.
henke37 is offline   Reply With Quote
Old 12-12-2009, 06:22 PM   #9
loganbest
Registered User
 
Join Date: Oct 2006
Posts: 41
Default

That's weird...it was there but it wasn't... FIXED.
loganbest 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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:44 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.