views:

224

answers:

3

in Flex if i have a loader class (i.e., XMLLoader) and a document class (document.as) and in document.as I'm instantiating XMLLoader

var ldr:XMLLoader = new XMLLoader(url);

... and on the document.as class I have a text box, which I would like updated with the progress from that XMLLoader is making by using URLLoaders progress event, continously. Meaning, the box would show the load in bytes that it is recieving

I'm not sure how to constantly push data out of an event and add it to another class. For example:

myLstnr.addEventListener(ProgressEvent.PROGRESS, getProgress);

private function getProgress():void
{
    // as progress updates, move it to document.as class's textbox
{
A: 

Your event handler (getProcess) must accept the ProgressEvent as a parameter. From that, you get the needed info. When you do, just write it out to the text field you want, e.g.

document.textfield.text = event.bytesLoaded;
artemb
Sorry, I think the question was misunderstood. You are right, in my example, I forgot to give getProcess() a paramater of event:ProgressEvent. However, my question was, moving that data from the Progress Event INSIDE the XMLLoader class to a text field in ANOTHER Class.(sorry for caps, just trying to put emphasis)
Tomaszewski
But what is the problem? You don't know how to get a reference to another object, which you want to push data to?
artemb
Yes, I think I did not write my question correctly. What I need to knwo is. In my main.mxml class, I have a variable that I want to update constantly from an external loaders class. So main.mxml has a "[Bindable]var something:String;" which is bound to a label control. I want that label control to get incremental progress udpates from the external class, specifically from the ProgressEvent
Tomaszewski
A: 

You can dispatch an event to the other class from inside your getProgress(). Creating custom events

CookieOfFortune
A: 

You will want to re-dispatch the ProgressEvent. You can use a custom made event to store your event object. So for example:

private function getProgress(event:ProgressEvent):void {
    dispatchEvent(new CustomObjectDataEvent(event, 'progress'));
}

Where CustomObjectDataEvent is a custom event class that you create that stores an object(the ProgressEvent) in your custom event object. Here is an example implementation of the custom event that stores this object:

package events
{
    import flash.events.Event;

    public class CustomObjectDataEvent extends Event
    {
     public var objectData:Object;

     public function CustomObjectDataEvent(objectData:Object, type:String, bubbles:Boolean=false) {
      super(type, bubbles);
      this.objectData = objectData;
     }

     public override function clone():Event {
      return new CustomObjectDataEvent(objectData, type, bubbles);
     }
    }
}

Check out: http://livedocs.adobe.com/flex/3/html/createevents_3.html for more information on dispatching custom events.

bkildow
ok so then how do I push/pull the data out of the CustomObjectDataEvent? In other words, how do I then, on main.mxml, do I update a control incrementally of how many bytes have been loaded?
Tomaszewski
thanks by the way...
Tomaszewski
ok wait, i got it to work. I got it to work by extending the EventDispatcher and the dispatchign a custom class. However, I do not understand how this will work. It seems like it could be a better method, but I just don't understand it.
Tomaszewski
actually this brings up a point. What is the difference between creating my own events inside an external class file, versus adding Event Listeners on the class's public object from the main.mxml?
Tomaszewski