I read a lot about dispatching events and still cant get it to work. I have a class and want it events to be visible for other classes which using this one. Main class:
import special.proxy.ProxyStream;
public class testproxy extends Sprite
{
var textspace:TextField=new TextField();
var proxydata:*;
public function testproxy()
{
textspace.autoSize="left";
textspace.text="ready";
addChild(textspace);
try
{
proxydata=new ProxyStream();
addChild(proxydata);
proxydata.load(proxyurl_string, fileurl_string);
proxydata.addEventListener("COMPLETE", complete);
proxydata.addEventListener(Event.COMPLETE, complete);
}
catch(e:*){textspace.text=String(e);}
setTimeout(checkProgress, 2000);
}
function checkProgress(){textspace.text=proxydata.progressstate;}
function complete(){textspace.text="loaded";}
}
Class which dispatching event for main class:
import flash.events.*;
public class ProxyStream extends Sprite {
public var progressstate:String="0";
//[Event(name="complete", type="flash.events.Event")]
[Event(name="complete", type="flash.events.Event.COMPLETE")]
private function complete(e:Event):void {
progressstate="1";
dispatchEvent(e);
dispatchEvent(new Event("COMPLETE", true, true));
//dispatchEvent(new Event(Event.COMPLETE, true, true));
//dispatchEvent(new DataEvent("COMPLETE", false, false, e.target.data));
}
}
As we can see, proxy data is added to display list. And yes, function complete firing, because when I check progressstate after 2 seconds, it has value 1. I tried many different ways of dispatching event. I still cant get this class event in my main class. I also want to be able to send data with this event if its possible without making additional own event class. Thanks for any help.
Your complete event lister does not have the correct parameters. It should be
complete(event:Event):void, notcomplete()