Sending events from instances of the class

Hello
I have problems with dispatching events from instances of class.
In a simple MXML application, I added an event listener for a custom event.
In accordance with the rules of good practice MVC, I have a template with a single instance (singleton pattern) class. This instance has no reference to my MXML component. When my model receives the data from the server, I want to send an event of this forum (which isn't in the displayList!). I could solve that problem with a model of the observer, but there is no way to any shipment of the event?
Help much appreciated!
Dany

Hello Cesare,

It works indeed! Thanks a lot for your help here!

Dany

Tags: Flex

Similar Questions

  • What is the best way to run multiple instances of the class containing infinite while loop?

    Hello

    I have a several instances of the class (say a, b, c,...) that have the same parent and I want to run the same methods overridden to all instances in parallel.

    For example:

    a.init ()-> a.run ()-> a.stop ()-> a.run ()-> a.stop ()->

    b.init ()-> b.run ()-> b.stop ()->->->

    c.init() ->           ->             -> c.run() ->               -> c.stop()

    ...

    See the attachment for more details.

    The problems are now:

    1. the 'run' - method does not return until it receives the external trigger

    2. everything to run methods return in a different time

    1 chip means I can't use autoindexed for loop because in this case b.run () will have to wait before the end of a.run (), right? Is it possible to run to the loop in parallel?

    2 chip means that an object must be able to run and stop independently from others.

    What is the most elegant solution? The solution copy - paste in the attachment works for 3 instances, but there are currently 10 and more is coming.

    Juha

    In fact, what I wanted to know was "how to add the 'P' loop '... Easy, after you ask the right question.

    In the attachment, there is a test.vi that has two numerical indicators in a certain time-infinite loops. If I leave the parallelism, the two digital are incremented infinitely. If I don't allow parallelism, only the first is incremented (he never leaves the infinite while loop).

    To solve my original problem, I can make an init-start-stop branch within a loop-parallel-indexing for and make sure that there are the same number of instances of loop as there are objects in my array of objects (object array is an autoindexed in the loop for).

    Also good point about the vis environment. I should also add that.

  • Passing a value to an instance of the class

    I'm trying to pass a single value to an instance of a class, but eventually send the same value to each instance. The class creates a button. When you press the button I want to retrieve the value sent to the instance. myVar is a public variable declared in the class. I pass the value using the class:

    public var myClass:SomeClass = new SomeClass();

    .

    .

    counter ++

    myClass.myVar = counter

    When I press a button that exists in the class, I want to be able to recover myVar, but the value that comes out is always equal to the value that was generated for the last instance. So if I generate 5 cases, the value of myVar is 5 for each button I press. How can I make the unique value of myVar stay with the instance?

    If you are writing a class with an instance var such as

    public class mybox.

    {

    public var int value;

    }

    then in one method of another class, you can write

    var myBox:MyBox = new MyBox();

    myBox.value = 17;

    and the value 17 is stored in this one instance of MyBox.

    You could also make it possible to set the value of the box in the constructor:

    public class mybox.

    {

    public void MyBox(value:int)

    {

    Super();

    This.value = value;

    }

    public var value: int

    }

    var myBox:MyBox = new MyBox (17);

    Gordon Smith

    Adobe Flex SDK team

  • How to refresh a screen without making a new Instance of the class

    Hi all

    Please help me.

    I need to refresh a screen of components such as the text box, list etc without (pushing the new instance of the class) using the old instance.

    I use:

    UiApplication.getUiApplication () .invokeAndWait (new Runnable() {}

    public void run() {}

    invalidate ();

    }

    But it will not refresh the screen components.

    I need to change the label of the text box, choice of etc group on click on the Refresh button.

    Please suggest me

    Thank you

    Again, I agree with BBDeveloper, just wanted to add an alternative solution.  You must have the code that sets the values in those fields anyway.  You can separate the code that adds the fields to the screen of the code which sets the values in these fields, place the code that sets the fields into a separate routine and call this routine to during the construction of the screen and the screen refresh.

  • means of an instance of the class to ask what is the name of the instance?

    Hey. I have a class that needs to create a movie clip on the stage. Because each instance of the class can have 1 clip of film on the scene at a time, it seems reasonable that I have the instance create a clip with its own name, preceded by the prefix with "mc_" or something of the sort.

    Here is where I don't know what to do... How can I get this information? For example, when you one dealing with an XMLNode, you can simply use...

    The_Answer = xmlNodeInstance.nodeName;

    ... I know the analogy fails, but I hope you know what I'm looking for.

    Thank you!

    MovieClips have a _name property AFTER they are instantiated.

  • knowing that an instance of the class is created from

    Can someone give me some advice. In the actions script, 3.0 I would retrieve the class of the two instances and then compare. Is there a way to know what an instance of class is composed of?

    See if getQualifiedClassName() is what you want.

  • Button send email from preSubmit of the event

    I am working on a study that contains the send e-mail button.  When a user clicks the button, their study should be tested for three conditions.  The first is that all mandatory questions have an answer.  These answers are yes/no radio buttons.  The second is that if the user has answered 'No' to one of the first seven mandatory questions, they must submit a corrective action form.  A message box appears to inform the user that they must fill out the corrective measures which becomes visible, as the last page of the survey, in the click event of the radio button 'no '.  When the user has entered the field of corrective measure a response and click send by e-mail once again button, the investigation should then let them finish the presentation of messaging.  The following code is in the preSubmit action form:

    Form1::preSubmit:form - (JavaScript, client)

    If (CorrectiveAction.presence == 'visible')

    {

    If ((CorrectiveAction.rawValue == null) |) (CorrectiveAction.rawValue == ""))

    {

    xfa.event.cancelAction = true;

    xfa.host.messageBox ("Please complete section of corrective measures at the end of this form.");

    }

    }

    I currently have following problems:

    In Adobe Pro 9:

    The send e-mail feature is not cancelled if the user has not filled the form of corrective action.

    In Adobe Reader 9:

    The send e-mail button does not at all, but the message box is displayed if the box 'no' has been selected.

    You can provide any assistance would be greatly appreciated.

    Change the property type button instead of the button send email, and then assign the Submit control Type.

    Tab submit, together submit it as to what your condition is... XML / PDF etc...

    Instead, copy the following code in the preSubmit event after all your validations are completed.

    Declare variables to hold the values

    var strToAddress, strCCAddress, strSubject, strMessage

    Assign values to the variables above according to the needs...

    event.target.submitForm ({cURL: "mailto:" + strToAddress + "?"}) subject = "+ strSubject +"& body ="+ strMessage, cSubmitAs: 'PDF'});"

    Sample is here...

    https://Acrobat.com/#d=pFyQRZ * C1TYAlU * 8VOpV8A

    Thank you

    Srini

  • How to access the BitmapData instance on the class that extends the charger?

    Hello. I use Flash CS6 to create an AIR application that loads an image from the computer, and then a pixel counts using its bitmap data.

    MyImg is a class that represents the loaded image.

    package com.utils {}

    import flash.display.Loader;

    SerializableAttribute public class extends {charger MyImg

    public void MyImg (): void {}

    }

    }

    }

    In my main class I manage the selection of files and loading.

    private var _myImage:MyImg = new MyImg();

    private var _file:FileReference;

    private var _fileTypes:FileFilter = new FileFilter ("Imagens: (*.jpeg, *.jpg, *.gif, *.png)", "*.jpeg;") *.jpg; *.gif; *.png");

    When the user clicks on a "load image" button on the stage, it calls loadMyImg().

    public void loadMyImg($e:MouseEvent):void {}

    chooseFile();

    }

    The user then selects the file he wants to do.

    private function chooseFile (): void {}

    Inasmuch = new FileReference();

    _File.addEventListener (Event.SELECT, fileSelected);

    _File.browse ([_fileTypes]);

    }

    Once you have selected the file, it is loaded as a byte array.

    private void fileSelected($e:Event):void {}

    _File.removeEventListener (Event.SELECT, fileSelected);

    _File.addEventListener (Event.COMPLETE, fileLoaded);

    _File.load ();

    }

    When it finishes loading it loads the byte array in _myImage.

    private void fileLoaded($e:Event):void {}

    _File.removeEventListener (Event.COMPLETE, fileLoaded);

    _myImage.contentLoaderInfo.addEventListener (Event.COMPLETE, dataReady);

    _myImage.loadBytes (_File.Data);

    }

    Once it's done I try to use the _myImage BitmapData, but cannot...

    private void dataReady($e:Event):void {}

    $e.target.loader.contentLoaderInfo.removeEventListener (Event.COMPLETE, dataReady);

    trace ($e.target + $e.target.content + $e.target.content.name + $e.target.content.bitmapData); Returns [object LoaderInfo] [object Bitmap] instance 155 [BitmapData object]

    trace (_myImage + _myImage.content + _myImage.content.name + _myImage.contentLoaderInfo + _myImage.contentLoaderInfo.content.name); instance of [object LoaderInfo] 155 155 instance [object Bitmap] returns [object MyImg]

    trace (_myImage.content.bitmapData) //compiler error: 1119 of bitmapData property possibly access not defined through a reference with static type flash.flashDisplay:DisplayObject.

    error //same trace (_myImage.contentLoaderInfo.content.bitmapData)

    }

    I don't understand what I'm doing wrong. Instances have the same name so that they are identical. They both trace as bitmaps, yet when I didn't access it from the event I do not get the bitmapData. Can someone tell me what I am doing wrong? I need to use the bitmapData of the classroom MyImg. I guess I could create a BitmapData variable in the class and give it the value of $e.target.content.bitmapData, but I still want to know why it can't be simpler.

    Thank you!

    Cast _myImage.content as bitmap:

    Bitmap (_myImage.Content)

  • Access to the Instance of the class within the component TileList DataProvider?

    I have a TileList component that is powered by a DataProvider.  The DataProvider place a class from the source (and the corresponding MovieClip) in the TileList in the form of Visual and interactive objects.

    dpChords.addItem ({label: tt, source: ChordUnit, data:, scaleContent:true});})

    How to pass unique values for instances of the 'ChordUnit' within the TileList?

    public void setChordBin(song:int):void {}

    var dpChords:DataProvider = new DataProvider();

    var i: uint;

    / / determine the game of rope

         If (song ==-1) {}

    activeChords = allChords;

         else {}

    activeChords = songChordSets [song];

         }

    / / filled dataProvider

    for (i = 0; i < activeChords.length; i ++) {}

    var TT = activeChords [i];

    dpChords.addItem ({label: tt, source: ChordUnit, data:, scaleContent:true});})

    }

    chordBin.dataProvider = dpChords;

    FORMATTING

    chordBin.columnWidth = 105;

    chordBin.rowHeight = 115;

    chordBin.direction = ScrollBarDirection.HORIZONTAL;

    chordBin.setStyle ("contentPadding", 5);

    chordBin.setRendererStyle ("imagePadding", 0);

    chordBin.scrollPolicy = ScrollPolicy.ON;

    / / set of style for labels

    chordBin.setRendererStyle ("textFormat", textFormat2);

    / / set the background skin

    chordBin.setStyle ("skin", lightBackground);

    set the CellRenderer

    chordBin.setStyle ("cellRenderer", MyTileListRenderer);

    EVENTS

    chordBin.addEventListener (ListEvent.ITEM_ROLL_OVER, chordBinItemOVER);

    chordBin.addEventListener (ListEvent.ITEM_ROLL_OUT, chordBinItemOUT);

    chordBin.addEventListener (ListEvent.ITEM_CLICK, chordBinItemCLICK);

    }

    I think you should you rewrite ChordUnit class so that path is defined. There are several way to do. One of the ways can be:

    public void ChordUnit(url:String):void {}

    imagePath = url;

    loadDiagramImage (imagePath);

    }

    So, in your setChordBin you can instnatiate directly:

    for (i = 0; i

    var TT = activeChords [i];

    dpChords.addItem ({label: tt, source:new ChordUnit("youUrl.blah"), data:, scaleContent:true});})

    }

  • Reassign the variable to an empty instance of the class class

    When I declare a class variable

    private var myVar:MyClass = new MyClass();

    It creates a new instance of this class, which will trace as [object MyClass].


    However, as soon as I assign to something

    myVar = thisOtherVar;

    It will trace now as [Object thisOtherVar].

    I need to get back to where it is just an instance of the empty class "empty", if it has any sense at all.

    How can I do this? Thank you!

    I think you're overloading the things how I would do is to have two classes: letter class and (for lack of a better term) of Word, both extends Sprite.

    Class letter distributes the mouse (drag start) press events and on the release of mouse (stop drag).

    Word class look over the events. On the event of publication (drop), if the letter fell into one of his empty housing fills the array of letters. On the Press Conference (pick up = start drag) if the letter was in one of the slots, lift the range of letters.

    When you press the button 'Search' you use the table of letters in the word class to see if it forms a Word. Simple

  • Creating instances of the class customized for XML nodes

    Hi guys,.

    I'm trying to load an external XML document in my application and create an instance of a custom class for each node in the XML file based on the value of some of their elements. Instances created later will end by in a DataGrid by the way. The problem I have is there seems to be several ways to make small parts of it and I have no idea how do them all gel. Initially, I use HTTPService to load the XML file, but I've seen people just use a XML object. Then, after that, I put the XML loaded to an ArrayCollection collection initially, but others used XMLList or XMLListCollection. I have no idea of what is the best way to do it.

    Finally, when I created all of these instances by looping through XML and their creation how I'll make them bindable to the DataGrid? I guess I'll have to group together them somehow...

    Any help would be greatly appreciated. Thank you

    Create a class customized for your 'point' of dataGrid dataProvider objects
    * Use HttpService to get the XML code.
    * use an e4x expression for the child nodes of the xml in an XMLList: myXML.children () or myXML.myNodes;
    * use a for loop on the XMLList
    * inside of the loop, create a new instance of the custom class
    * Of the [i] myXMLList, obtain all necessary attribute values and assign them to the appropriate properties in the instance of the custom class.
    * always inside the loop, use myArrayCollection.addItem (mycustomClass) to add the element to the collection of the dataProvider ArrayCollection.

    Tracy

  • By the way the main instance of the class

    Hi all, I have a master swf that loads different SWFs, one of these swf files is the home page with navigation elements, how can I pass a reference to the home.swf in charge of the main.swf that contains the methods of load?

    I try to create a var in the class home.swf with the main.swf class type, but the home.swf give me error that cannot find other objects contains in the main.swf

    Thank you

    rS

    Since the main timeline of the SWF loaded (home.swf), you must use

    MovieClip (this.parent.parent) .mainclassfunction ();  assuming that your document class extends the movieclip class.

  • Theory of the class from a perspective of creators

    Brief history of me. I used flash since version 3 as a designer. There, you go right on the question!

    I want to know how to make an object that I manually placed on the stage of the library with a class attached to it, to interact with the Document class?

    So, I'm basically dragging the element on the stage and this point has a related class and the Document class with all its subclasses should know that it exists.

    -----

    Now I'm dabbling with making Geometry Wars to learn AS3 Classes and it's been very fun, I created the Document class, my enemies and the player 1 spaceship. I worked on my various subclasses, and everything has been added to the scene by AddChild() and by all subclasses being created through the Document class...

    Each object of class was related to the Document class that all things were created by him or through subclasses under him. So I had to do what I wanted control. , However, I never see are generated dynamically at the stage of the elements. As a designer I want to liven things up here and there and then at specific times may take control of this issue with it's classy attached, but I want the Document to have a link at this point.

    Also everyone please stop generating text dynamically boxes all the time. Simply create a MovieClip with the elements of form on this subject if it is a form that will not change at all in the layout. But it opens on the same type of questions, the elements are not be created and added to the stage as objects so you have to do to understand the points of the it class MovieClip exist, I would by the name of the Instance but is this dirty these days in AS3...

    All this makes sense? : S I ask me questions that are perhaps confusing Code AS3 by looking at other designers?

    Cheers you much :-)

    Well, if mcGoatFace is an instance of pants, then I do it like this:

    SerializableAttribute public class Turgutreis extends Sprite

    {

    private var mcGoatFace:Pants;

    public void MainBase()

    {

    addEventListener (Event.ENTER_FRAME, myEnterFrame);

    }

    private void myEnterFrame(e:Event):void

    {

    If (mcGoatFace)

    {

    mcGoatFace.MoveX ();

    }

    trace ("the mcGoatFace which =" + mcGoatFace.GetX ());

    }

    }

    Why would you have to give it another name? Of course if you play with polymorphism then you have me. Not sure how to set up mcGoatFace in your library to bind to the class of pants, right?

    Also, personally, I don't like the use of the pre/post difficulty of things, more so than if mcGoatFace is that an instance of the class of pants shouldn't the name be pantsGoatFace? But personally I just use goatFace myself.

    Classes should be captialized also, but no instance of the class so even if you were to use something as you had before, I would do that

    private var _quickShape:Pants;

    Yet once it is a personal preference. I put underscore to help me know what properties are private and which are not. And lower case lets me know that this is not a class but and an instance of a class.

    Finally you are not in communication with the class, you communicate with an instance of the class! It's a subtle difference, but a real difference. The methods GetX and MoveX are not the methods of the class, they are the methods of the instance class. BTW, again I would start all the method with the lowercase names. getX() and moveX(). These two methods require that you have an instance of the class of pants. You cannot say getX() it must be somePantsInstance.getX () so that the method knows where to find this x from - specifically somePantsInstance.

    Other classes that you know, such as the math class, have methods that belong to the class and no instance of the class is required. So, if you want to round a number do you this:

    trace (Math.Round (5.5));

    You do not have it.

    var myMathInstance:Math = new Math();

    myMathInstance.value = 5.5;

    trace (myMathInstance.Round ());

    Or, however it would be built.

  • How to get the class Loader of Progress event

    I was charge test.swf file threw Loader class. How to get the class Loader of ProgressEvent, IOErrorEvent.

    function getLoader() {}
    var loader: Loader = new Loader();
    loader.contentLoaderInfo.addEventListener (ProgressEvent.PROGRESS, progressHandler)
    loader.contentLoaderInfo.addEventListener (IOErrorEvent.IO_ERROR, ioErrorHandler);
    var request: URLRequest = new URLRequest ("test.swf");
    Loader.Load (request);
    }
    function progressHandler(event:ProgressEvent):void {}

    get the class loader
    }

    function ioErrorHandler(event:IOErrorEvent):void {}
    get the class loader
    }
    getLoader()

    the event target has a property of charger:

    Event.Target.Loader

  • Event Bubbling: Relay of the custom events

    Background:
    The bubbling in the action script 3 event causes an event to travel from the responsible subject through all its objects from parent to the root application. The event then moves back down to the original object.

    Goal: keep the data, the controller and the loosely coupled views
    1. When display objects are instantiated, they send an event by saying that they need certain information. The event has the type of information they need.
    2. the purpose of data capture this event, determines if it it has in memory. If it isn't, it retrieves information from a web service and pushes the result in a table.
    3. once the result in memory, it takes an event that contains the index of the result table.
    4. the view captures the result, out of the index and use it to link to the correct array element

    Result: The display is automatically updated every time that the data object is called by the web service with an update.

    In this scenario, nor the view or the data can be parents of each other, but each must be able to respond to the events of each and other. The reason is so that I can have multiple views generated dynamically, using the same data.

    Question:
    If the data (model) and the views are children of the same application, how does one maintain loose coupling between them?

    Current solution:
    The only thing I could get to is having the object application or controller catch all custom events and then their reconsignment to the children. The problem is that it is messy.

    I could also design a handler class that would have the forwarding of events to the right of the child hierarchy. I could include a private string variable that would capture the name of the object responsible for when my custom event was known as the class handler could do dynamic mapping.

    Is there a better solution?

    Thanks - I posted the question on something awful and someone suggested that I use a microwave recommended architecture on Adobe Labs called Cairngorm , I'll go through the documentation and give it a test drive this week.

Maybe you are looking for