ActionScript 3.0 :: Parents Listening For Events
Jan 25, 2009
what the most efficient method is for listening for events up and down a string of parents and children? Example:
(these are parents from left to right) Main Sprite -> Child A -> Child B -> Child C
Child C fires and Event - what's the best way to have Main Sprite listen for it?
1) Make Child B and C "public" so Main Sprite can attach a listener all the way down on C (_childA._childB._childC.addEventListener)
2) Child C's event triggers a Child B event that triggers a Child A event that Main Sprite listens for
View 5 Replies
Similar Posts:
Oct 20, 2011
I'm working on a web app built in Flash AS3. At a high level - the app has a main screen, and several "modal dialog"-type screens that pop-up to manage various user interactions. (This is a similar pattern I use in most of the apps I develop...) Typically - when the user clicks a UI control on the dialog screen (e.g., button, text box, slider bar, etc.) - the main screen needs to react, or manage the consequences. It seems like there are two general ways to handle this: Have the dialog screen dispatch events that the main screen listens for Allow the dialog screen to call functions in the main screen when those controls are clicked (which requires that the dialog screen maintain a reference to the main screen, and that the functions in the main screen are public)
In general - I understand that one of the key benefits of the first method is that the dialog screen isn't so tightly coupled; it's only responsibility is to broadcast the event. This would allow me to more easily use the dialog class in other contexts, or applications. But for many RIAs I develop - a particular screen is SO SPECIFIC to the the application that there's no chance I'd ever reuse it in another application. So, the "easy re-use" benefit is minimal. So - if you eliminate that benefit - which method is actually better? (More performant, less resource-intensive?) For example - if I use events, then Flash needs to manage many listeners for events that may never occur. So - it might be more efficient if the dialog window could call a function in the main screen directly, instead of dispatching an event.
View 3 Replies
Sep 2, 2010
I want to have a main logic class that listens for dispatched events from an assortment of other classes.
for instance: i have a parent Map class that contains X instances of a State class. When the user clicks on a State class, i want to dispatch an event CLICKED along with the name of the state.
now this Logic class will see this new event and process the name of the state and perform some other logic stuff. no matter what i try i can only get it to work where the State class listens for its own Dispatched event. Which to me seems a waste, i could have just manually called the function.
I have read so many tutorials online about custom events/ dispatching and they are being used in a basic one class example.
View 3 Replies
Oct 16, 2011
I have the Main class that imports my urlValidator class.My urlValidator class imports com.usual.swfaddress and thanks to the SWFAdressEvent fires the function dealing with the validation of the url.In some other class myMenu (child of the Main but on the other branch) I need to listen for the event of validation being completed.I'm importing myEvent (custom event) class to urlValidator and when the validation is complete I'm triggering the dispatchEvent.At the same time I'm importing the myEvent to myMenu class and trying to listen when the myEvent was dispatched (from urlValidator).
View 2 Replies
Sep 15, 2011
Basically I've build a small class that can be imported anywhere in the program and one of it's public methods dispatch a listener, which as I understand can be received anywhere. Is that correct? In my project I've got a menu which slides in and out. It's movement can be triggered mainly bu the buttons on the menu, but I also want to be able to controll it's movement from various places in the program. So i.e. it can slide in or out when something completely unrelated has been clicked. So I've got a class "SlidingPanel" and one of its children is class "SlidingPanelNavigation". SlidingPanelNavigation uses the class that only dispatches the Event, which should be listened in class "SlidingPanel" and the problem is - it doesn't.
My main class that holds the whole menu together:
Code:
package com.zeeto.menu {
import flash.display.MovieClip;
import flash.events.Event;
public class SlidingPanel extends MovieClip {
private var navigation :SlidingPanelNavigation;
[Code] .....
Why the SlidingPanel.slideMenu() isn't fired?
View 1 Replies
Jan 23, 2011
I am working on a simple project involving flex 4 and Mate framework. When I am including Mate event map in fx:declarations tag in mxml file, and when I fire up an event, Mate event handlers listen to events and act upon it.
The issue is this, in action script based project, when I instantiate the eventmap class(this is in mxml file only) and keep it in top and fireup an event, instantiated eventmap is not listening to event fired up from action script class.
View 2 Replies
Aug 25, 2009
I am making a game that uses MVC pattern. The game.swf is loaded into main.swf. I want to dispatch a gameOver event from the Model Class of the game.swf and have the main.swf(parent) listen for it but I can't get it to work.
I have game.swf dispatching events fine amongst itself just fine but I can't get the parent to hear anything.
I tried this in the main.swf
Code: Select allvar loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
function gameOver(e:Event):void
{
[Code].....
View 1 Replies
Apr 7, 2009
I'm creating an AIR application that loads a child SWF. The child needs to read keyboard input (for a game), which I usually do by adding a keyboard event listener to the stage property, like this: stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp)
However, the child SWF is apparently not allowed to access the stage property because the parent SWF owns the stage, so I get a security sandbox violation. So I need to do one of two things:
Bypass the security restriction allowing AIR to load SWFs that have an absolute path (local path), and allow that child to access the stage, orGet keyboard events to be heard by some display object other than the stage, without ever calling "stage" (this includes stage.focus).A few things I have tried already: Security.allowDomain() does not work. AIR thows an error saying that allowDomain doesn't work in the AIR sandbox. Also, adding the keyboard listener to the child's document class (then clicking inside the SWF) doesn't work.
View 1 Replies
Oct 30, 2010
Here's my code: [URL]
I'm using Flash Develop.
The trace command never gets executed. Why?
View 9 Replies
Jun 18, 2009
I've got a class like this:
class Foo extends UIComponent {
var someDispatcher:*;
...
}
And I want to listen for events fired by someDispatcher... But, of course, someDispatcher may not be bound until "later":
<components:Foo someDispatcher="{someOtherComponent}" />
What's the best way to listen for events from someDispatcher?I know I could bind to someDispatcher, then wire up the event handlers when it's updated... Or I could use getters/setters...
View 2 Replies
Jul 6, 2011
I need to register events in flex and listen to them in java script. Is there any way other than using external interface.
View 1 Replies
Aug 29, 2009
I have a menu movieclip and an externally loaded swf on my main stage. The menu mc needs to control the externally loaded swf. For example the swf plays and pauses, then when any of the menu buttons are clicked the swf needs to play thru and be removed. currently I am dispatching an event for each button clicked with a switch statement. In the main timeline I need to listen for each of theses events and based on what button is clicked proceed to the correct content frame. How can I listen for different events and run one function that based on which event is registered perform a task with a switch or if statement?
View 4 Replies
May 1, 2010
I've got a class like this:
class Foo extends UIComponent {
var someDispatcher:*;
...
[code].....
View 0 Replies
May 5, 2011
`i'have a problem with listening events dispatching from their child classes. for example i have contentManager object which is controlling content at the top level of stage. it has a imageGallery object and in the imageGallery objectthere ise a collectionLoader object which is loading images.
now i want to add one preloader to contentManager which always listen for ProgressEvent. when the progressEvent dispatched i want to preloader going to active. becouse there is another objects that are loading images or other kind of files. i think it is a good apporach to solve preloader issue. so my problem is, when collectionLoader object loading images with using queLoader. my QueueProgress event dispatches ProgressEvent evey time, but my preloader object stand at the 2 classes up level, doesn't percive this event.
View 3 Replies
Jun 27, 2011
I'm creating a swf, that has a parent class and a child class. The parent class has a button, that dispatches a custom event and I want the child class to list for this event, but when I dispatch the event the child class does not hear the event has been dispatched.[code]The register EventListeners() function is in the child class.I know events can bubble up the display list but how can then go down the list?
View 1 Replies
Sep 20, 2010
I currently have an over, out and click event for 8 different objects. The over and out events are identical for each (tween expands object and then shrinks it back for the out state).I have previously asked for an easy way to declare those events, and now I was looking for an easier way to handle them.
Here's my code:
//-----------GARAGE
function growGarage(e:MouseEvent):void{
scaleTweenX = new Tween(map_garage, "scaleX", Elastic.easeOut, 0.648, 1, 0.5, true);
[code]....
I've tried using a single function and then using "this" as the object of the tween but that expanded the entire stage.
View 1 Replies
Nov 10, 2009
ok, my Digital arts class is making a flash project, and im like the only one actually making a game, so im pretty much alone. i got a lot of help from the people on the AS3 forum, but im pretty sure that my question is too easy to put there. so, i have an array, and it basicly puts a spike on the screen at a random Y, and moves it across the screen, but, when i hit a spike, and ti goes to the you lose screen, the loop keeps adding children, and putting them on the screen, is it possible to just say stop adding children, and go to the next frame? i have a break, but when i stop colliding with the spike in the next frame, the spikes start coming again. also, can i totally reset the movie? cause when i just go to frame 1, the array plays itself ontop of itself and it gets twice as hard
View 2 Replies
Sep 2, 2011
I want to get the full parent node on a result of a search.
XML example:
<ItemNodeCollection>
<MaxProf>1</MaxProf>
<ItemNodes>
[Code].....
How can I achieve this expected XML result?
View 6 Replies
Mar 28, 2010
graphicsSpace.graphicsInnerMenu.selectFolderMenu.imagesButton.addEvent Listener(MouseEvent.MOUSE_UP,imagesPage_change);function imagesPage_change(e:MouseEvent):void{
[code].....
View 6 Replies
Mar 30, 2010
I have a sprite within a movieclip that externally loads an image, how can i change the parent of the sprite to display on the main stage?
View 1 Replies
Feb 17, 2009
I basically have a large bar of items that fills up dynamically, they are all added to a dispCont movieclip as a container. When you click on one it gets pulled to the front, scales up and I want all the unselected Items to blur or become semi transparent. So i figured i could just tween the dispCont object, however this affects whatever is brought to the front, so i want to switch that into a new MovieClip called centerCont. Here is the code, ive been trying different things, I could just use a little input.[code]when I click on it because i am trying to set event.target.parent = centerCont;otherwise, uncommented and that removed i get Code:1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject.
View 0 Replies
Mar 5, 2011
Seems simple and I've searched but can't find the answer to this simple problem.
Loading map-.swf into main.swf. I want to use a variable from main inside map-1 to indicate which xml file to load.
First problem, I'm coming to AS3 and if a variable isn't declared, then errors, can't compile. So do I have to declare this variable in both swf files?
And well I've tried declaring the variable in the loaded swf and it still doesn't work.[code]...
View 3 Replies
Dec 19, 2009
There is the stage, the level object then the player object in the level. The player object has a sub-object that is a weapon. When I fire the weapon a bullet is to be placed on the level stage. At the moment I have this code in the weapon class when the weapon is fired.
[Code]....
(In case it helps you know my skill level, I'm currently reading Foundation Game Design with Flash by Rex van dur Spuy and am a PHP web developer, also played around with Flex - ActionScript is still new to me)
View 5 Replies
Dec 10, 2010
I would like to know is there a way to iterate through all parents in a display object.I need to do this because i am loading swfs to application and swfs have different number of nested movieClips and i would like to be able to access loader properties like width and height dynamically from within any depth.
View 2 Replies
Oct 19, 2010
Okay, here is the relevant files for a game I am making and their structure: -Stage -->MainMenu.as --> NewGame.as --> beachArea -->barrel.as.................................................. ......-->player.as.................................................. ......--> pistolBullet.asSo, am trying to detect when a bullet hits a barrel. I was going to use the hitTestObject() functionI got as far as trying to actually access the properties of an instance of barrel from the pistolBullet.as and seem to be a little confused as to my findings.. Can anyone explain to me why the last trace function returns undefined?pistolBullet.as:
Code:
trace("pistolBullet.parent: " + this.parent);
trace("pistolBullet.parent.beachArea: " + MovieClip(this.parent).beachArea);
[code].....
View 1 Replies
Apr 14, 2012
I'm making a game in action script 3. In it, I have an actor class from which player and enemy classes will be derived. I'm doing this so that unless I need to provide specific AI or fancy behavior (such as for bosses), I can just make a new clip in the library for each enemy without making an actionscript file.
However, I've run into a problem.
Whenever I try to pass arguments to the construction of an enemy (make it spawn with more health), I get error 1136 (Incorrect number of arguments.)
This is because the constructor created automatically at runtime doesn't have the same arguments as it's parent class. Is there any way to get around this without making a class file where I copy and paste the parent constructor function for each of my hundreds of enemies?
View 2 Replies
Oct 28, 2009
we have java and flex projects at work. We currently have 1 base pom that contains the configurations we want to use for both projects. Problem with this is: flex projects inherit configuration for javadoc and pmd for example, which they do not want.
I want to do this a bit more clean and have a real base-pom and then a java-base-pom and a flex-base-pom. But how does this work in a multimodule that has both a flex part and a java part?
We have plugins to our own application where we use the following structure:
my-plugin
my-plugin-client (flex)
my-plugin-server (java)
The my-plugin just contains a pom.xml with section. I would use the my-plugin pom.xml as a parent to both, but then I cannot also use the java base-pom or the flex base-pom also as parent.
View 3 Replies
Jan 18, 2011
My parent ActionScript3 file has functions like these:
package
{
*lots of import.*
public class Tabu extends MovieClip
{
[Code]...
View 1 Replies
Apr 25, 2004
I have several buttons on an externally loaded swf that work fine but I'd like to clean up the code if possible. Is there an better way to target the mc other than using multiple _parents?
Code:
on (rollOver) {
_parent._parent._parent._parent._parent._parent._parent.expression.gotoAndStop (2);
} on (rollOut) {
_parent._parent._parent._parent._parent._parent._parent.expression.gotoAndStop (1);
}
The thing is I am not exactly sure if this mc is going to remain an external swf or if it will eventually stand alone, which is why I haven't targeted the root at its level. I'd like it to work either way if possible.
View 1 Replies
Mar 27, 2009
This may well just be because it can't be done but here goes.Does anyone know of a way that I can make a MoviecClip "visible=false" whilst stopping just one of its children's, children's, children...etc from also going invisible.I am aware that it can be done by setting them all individually but this will take a lot of code (and I like tidy code...and I'm lazy), and I am reluctant to use a loop as it will interrupt the animation that is going on at the time.
View 2 Replies