ActionScript 3.0 :: DispatchEvent Versus A "State" Class?

Sep 17, 2010

Like most Flex/Flash Builder developers, I have been using the dispatchEvent method to communicate between different classes of an application. And, that works fine, but, I have been toying with a different idea about inter-class communications and would like you to shoot it down, if you can.

Why not have an application "state" class, instantiated as a singleton, which holds the information that is needed by the application's various classes? Examples would be current user and session, currentState of the parent application, selection criteria, data providers, etc. Each class would, of course, have to be aware of this state class. Each class in the application would post its relevant state to this "state" class, and likewise each class could establish listeners for changes to the relevant objects therein.

It just seems to me that, rather than dispatching events, setting up listeners that in turn fire off a listener method, I could instead bind, for example, a datagrid to the state class' relevant data provider, or whatever is needed. In other words, all "listening" and binding is performed against a single state class.

View 9 Replies


Similar Posts:


ActionScript 3.0 :: DispatchEvent Versus Function Call?

Aug 21, 2008

I'm still wondering which method is the best use:

Event Dispatcher:

PHP Code:

package
{
import flash.events.EventDispatcher;
public class Test

[code]....

View 8 Replies

Flash :: DispatchEvent In Static Class - AS3

Jan 6, 2012

I can't use dispatchEvent in my static class, I was wondering if anyone knew how I can achieve similar functionality or if it's possible at all to call dispatchEvent from my static class? I basically want to inform my action script code in my flash file when functionality in my static class is complete.

View 4 Replies

ActionScript 3 :: DispatchEvent Does Not Work In Secondary Class

Jan 14, 2011

I have a SWF called Application.swf that loads another SWF called jeu.swf. My main class (don't know how to call it haha), is called Main.as. Another class is called actionObjets.as. When I call:
dispatchEvent(new MicroJeuEvent(MicroJeuEvent.JEU_TERMINE, 8, ""));
It works perfectly from Main.as, it works perfectly.

But when I call it from actionObjets, it doesn't work. No error either. I tried putting this line in a static function, doesn't work either. Why can I dispatch an Event from my main class and not from another one? I'm not a programmer and I just don't get a few of the basic principles of as3. Is there a way of doing differently?

View 1 Replies

ActionScript 3.0 :: Transferring Values From One Class To Another Via DispatchEvent?

Nov 9, 2009

transferring values from one class to another via dispatchEvent.

main.fla
code/main.as (Doc class)
code/game/card.as
code/game/board.as

I can communicate an event between any of them fine using a dispatchEvent and addEventListener, and I can get values from the card & board actionscript files into main.as using e.target.*

However for some reason I just cannot get a value to send from main.as to the card or board classes using this same method. And I'm literally stumped as to why.

View 6 Replies

ActionScript 2.0 :: DispatchEvent With A Function Declared Inside The Class?

Jan 19, 2007

I've got a class where I'm using:

o.type = "focus";
o.target = "this";
dispatchEvent(o);

and then focus is a function of an object in the FLA.

I want focus to be in the AS External Class file but it won't trigger.

View 3 Replies

ActionScript 3.0 :: DispatchEvent - Create A Listener In My Main Document Class?

Jan 13, 2009

I'm trying to dispatch a custom event. So that my main document class can react when a nav button is clicked.I have a navbutton class which creates the dispatch's the event... and is handled by the onNavigate Method...

private function onClick(evt:MouseEvent):void {
//trace(_label.text + ": path = " + _projectNode.@path);
//trace(evt.target._label.text);[code]....

This onNavigate method works perfectly.... however when I try to create a listener in my main document class I don't "hear" the event.Here's part of the code from the main doc class...here's where I register the listener

this.addEventListener("NAVIGATE", doSomething);

here's where I should handle it...

private function doSomething(e:Event) {
trace(e.target.name);
trace(e.target._label.text);

View 12 Replies

ActionScript 3.0 :: Get The Instance Of The Class To Call The DispatchEvent For The PostTrace Function

Feb 8, 2009

How can I get the instance of the class to call the dispatchEvent for the postTrace function.

1180: Call to a possibly undefined method dispatchEvent.

Code:
package {
import flash.display.*;
import flash.events.*;

[Code].....

View 1 Replies

ActionScript 3.0 :: Implementing Versus Extending A Class?

Feb 24, 2010

I can't quite wrap my head around the differences. In what situations would I choose one over another?Specifically, I'm creating a sort of View component (in a very hack-y sort of way, I'm sure) that can redraw the interface with the same visual components (some of which change slightly depending on the mode) in 3 different modes: Normal, Small, or Fullscreen. The trick here is that both the Normal and Small modes can *also* go fullscreen as well, though you'll never be able to switch between Normal and Small in the same session (it's determined up-front).

View 1 Replies

ActionScript 3.0 :: Children Swf Timeline Code Versus Document Class?

Nov 23, 2010

I am trying to find out why when I place trace(parent); in the timeline of my child swf I get [object Loader]but if i place  trace(parent); in the constructor of the child swf's document lcass I get null.Why is this and how would I access the parent swf  from the child document class if it shows as null?

View 2 Replies

ActionScript 2.0 :: Navigation Class With ON State

Feb 17, 2006

I have used this navigation script several times in regular flash coding without problems (as in functions). Now I'm trying to put this code in a class for easier usage in future projects.Concept of the code is that I pass the instance of the mc in an variable so that I have an old and new location for enabling and disabling a "ON" state in an mc (vars : OldLocation && NewLocation).This is pretty basic stuff but I can't get it to work inside a class..Offcourse at the first click you will get an undefined because of no instance defined yet (I define it in the fla file).[code]

View 2 Replies

Flex :: Querying The State Of A Class's Listener?

Dec 13, 2009

I have instantiated a class (class1) that loads some data via PHP in an AS3 Flex project.I instantiate class1, which is asynchronous and utilizes a URLLoader() to obtain its data.Then I would like to instantiate class2, which needs to USE the data from class1, but when I simply instantiate it I find that class1's instance variable is not populated yet because I am calling class2 too quickly.How can I create such a dependency that will link correctly?I am really new to using listeners, but I am imagining a listener in class2 might be what I need?Or maybe I can pass a reference to the listener in class1 into class2?I also know nothing about dispatching events... is this the key?Here's an example in pseudo code:

var class1:myC1 = new myC1("http://some/url/to/utilize");
//this never shows up because it hasn't loaded at the time i request it
trace("the stuff from class1 is: ", class1.myXMLList);

[code]....

View 2 Replies

Flex :: Cancel 'seeking' State Of VideoDisplay Class?

Jan 12, 2011

I have a VideoDisplay instance playing some video. When I click on the video slider (also my component) the property videoDisplay.playheadTime is set and the videoDisplay.state goes from 'playing' into a 'seeking' state for a brief moment (the videoDisplay seeks for a new position and then plays the video again). Intended bevaiour. But if I'm (or any random user) fast enough, I can set the playheadTime again while the player is still in 'seeking' state. When repeated several times every click is enqueued and the videoDisplay jump on every place of the video I have clicked(this is happening in an interval about 10-15 second after my last click). When I use live dragging the videoDisplay, overwhelmed by seekings, goes into 'error' state.My question is - is there any way to cancel seeking state of the VideoDisplay class? For example player is in 'seeking' state, I set playheadTime, and the player forgets about last seeking and try to find the new place of the video.

View 1 Replies

ActionScript 3.0 :: Re-instantiating A Page Class In Original State ?

Nov 29, 2010

I'm making an app with pages set out as classes which extend the MovieClip class.

What I've got are back buttons and different pages which go to the same page, however... If I end up going out of a page and back into a page (specifically one with drawn squares and dynamic text boxes called from a web service), it seems to have kept all of the original information.

So far I've tried killing all of the children with a while loop targeting the index and also using weak event listeners - neither is working!

View 2 Replies

ActionScript 1/2 :: Dynamic InstanceName - Link The State Id's In The Xml Record To The State MovieClips That Make Up The Map?

May 12, 2009

I have a flash map that contains 51 movieClips, one for each state.Sample instanceName for a state (Alabama) would be: S_01
 
I have a XML record that contains specific info for each state.<stateID>01</stateID
 
I am trying to link the stateID's in the XML record to the state movieClips that make up the map.var stateInstanceName = 'S_' + stateID;
 
I was just trying to do a simple trace command to see if I could pull the _width of each state clip to see if I was linked up:
 
trace(mapInstance.stateInstanceName._width)

View 7 Replies

ActionScript 3.0 :: Flex - Loading Page As One State And The Main Application Design In Another State?

Apr 9, 2011

It's my understanding that view states can be useful when switching the layout of design elements. Such as, a loading page as one state and the main application design in another state. Is this the correct use of them? Additionally, I have a label in State1 and I cannot figure out how to access that label via actionscript. labelID.text = "New Text"; is not working.

View 2 Replies

Actionscript 3 :: Adding A Rollover State To A Spark Button When State Is Disabled?

Apr 14, 2011

I need to add a rollover effect to the disabled state of a Spark button. This way, users can rollover the button and know why the button is disabled.I think I would have to override ButtonBase's getCurrentSkinState. Is there anyway to test if a mouse cursor is over a disabled button?

View 1 Replies

Flex :: Get State Group / Actual State Object For Current?

Mar 30, 2012

I'm using Flex 4.5 and trying to take advantage of the new state groups feature. I have two States (call them readType1 and readType2) that both belong to the same stateGroup (call it readOnly). There are several places where I'd like to do something based on the current state, and it would be the same thing for the two read states. [code]...

View 1 Replies

Flex :: Set Size Of State After Moved Child State Using AIR?

Jul 25, 2009

In my air project i used current state size is width="441" height="358" . i have link button like Singin then move to singin state (currentstate='singin')

<mx:State name="signin">
<mx:SetProperty name="height" value="616"/>
<mx:SetProperty name="width" value="919"/>

So application resize into 616,919 . After that function finished move to current state like(currentstate='') But size not be changed . How can i set the size for current state?

View 1 Replies

Flex :: Fade All The Elements Of The Next State When Transitioning From Any State?

Jan 27, 2010

I want to fade all the elements of the next state when transitioning from any state.I tried different things but I can't get it to work. And I don't want to manually add transitions for every state.

Something like:

<s:Transition fromState="*" toState="*">
<s:Fade target="*" duration="500" />
</s:Transition>

View 2 Replies

Flex :: Creating State Children Before Switching To State

Mar 25, 2010

In my view I have a welcome screen:

[Code]...

Which is a pretty small component and I have panelContainer:

[Code]...

Whilst the user is reading the warm and fuzzy welcome note in the welcome state I want to be creating the big expensive panels state so taht when we switch there is no delay. Before the panels state is set panelView is null but I presume there must be an IDefferredInstance floating around somewhere that I can use to kick off the creation of the view. How can I get hold of it?

View 1 Replies

ActionScript 3.0 :: Make One Sound On The Over State And A Different One On The Down State?

Oct 4, 2008

I am trying to get converted to Actionscript 3 from AS2.In old versions of flash, you simply placed the sound in a keyframe inside the button on the over or down state. Worked fine, but not anymore.I guess the sound must be set up with actionscript and a listener.I understand linkage. how to make one sound on the over state and a different one on the down state?

View 4 Replies

ActionScript 3.0 :: Class Error - Roll Over And Roll Out State Isn't Working

Jun 7, 2009

Button class:

[Code]...

The Roll Over and Roll Out State isn't working.

View 3 Replies

Flash :: Access State In Flex "Current State" From Movie Clip?

Sep 3, 2011

i curious how to access state in flex "Current State" from flash movie clip??..so far i make movie clip in flash and it has button inside with name " button" and i put this flash file into flex in "state 1" flex application..i want to make event handler for "button" that trigger changing state from "state 1" to "state 2" in flex application..and in flex application i do not write anything because i have no idea how to deal with this stuff..

View 1 Replies

ActionScript 3.0 :: How To Use DispatchEvent()

Jun 1, 2011

where can i get a nice tutorials that is easy to understand? how to use dispatchEvent.

View 2 Replies

ActionScript 3.0 :: DispatchEvent From MovieClip?

Oct 28, 2008

I have a movieclip on my stage that I am using as a button toincrement an index number. I have declared a custom event class andI am passing the index to the custom event as a property.I have initialized the clips on the stage to listen for thecustom event and I am dispatching the event from the instance ofthe button being pressedEverything seems to be ok except my clips listening for theevent don't seem to be getting it. Can you not dispatch an eventdirectly from a movieclip instance on the stage? Do you have to doit from a .AS file class?

View 8 Replies

ActionScript 1/2 :: Connect Dispatchevent Between Two Swf's?

Jul 24, 2010

One single swf, imgdesc.swf is being loaded into the emptymcholder, by the moviecliploader instance.My order isfolioholdermc ---holds--> emptymcholder --holds--> imgdesc.swfWithin folioholdermc, I disabled buttons and lowered opacity, once imgdesc.swf was loaded, using onloadInit()Now  in the button inside imgdesc.swf. I called, this.unloadMovie(), which  successfully unloads the file, but I am still inside emptymcholder, though I actually want to go back into folioholdermc.tener to check for unloadMovie. But my problem is can I place this within folioholdermc, within the onloadInit() or maybe within the on(press) function which actually calls  the loader in the first place?? I need to enable the buttons within  folioholdermc, and increase opacity, once the imgdesc.swf is unloaded.

Within the onLoadInit() in folioholdermc I added
_mc.addEventListener("end",endClip);
function endClip() {  trace("end");  //plan to insert code to

[code]........

View 1 Replies

Actionscript 3 :: What Is DispatchEvent In Flash

Dec 6, 2009

i want to know what is dispatchEvent in AS3.

[Code]...

View 3 Replies

ActionScript 3.0 :: EventListener Is Not Being Hit By DispatchEvent?

Feb 14, 2012

I am making a class that is used to load levels, and while making the skeleton I thought I'd make some events for things like if there is an error while loading, or for when the loading finishes. So I did that and decided to test the event, via a test function that dispatches the event...but it just wont get picked up.

Here is the main class (a part of it anyway) where I'm adding the event listener.

ActionScript Code:
public function Game() {
this.addEventListener(Event.ADDED_TO_STAGE, Start);
this.addEventListener(LoadEvent.LOAD_COMPLETE, Bam);

[Code]....

why the dispatchEvent in the Load class and it's internal dispatcher class, is not getting to the eventListener in the Game class.

View 4 Replies

Actionscript 3.0 :: DispatchEvent Is Not Triggering?

Jun 5, 2010

why my dispatchEvent is not triggering. All I'm trying to accomplish is passing a variable from the document class to a sub class.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved