Hi,

This;

_view.addEventListener("xmlLoaded", doSomething);
_service = new MyService();

needs to be

_service = new MyService();
_service .addEventListener("xmlLoaded", doSomething);

Peace, Mike

On 5/23/07, Alex Harui <[EMAIL PROTECTED]> wrote:

   I don't think you're listening to the service


 ------------------------------

*From:* [email protected] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Daniel Freiman
*Sent:* Wednesday, May 23, 2007 7:29 AM
*To:* [email protected]
*Subject:* Re: [flexcoders] AS3: dispatchEvent from within event handler?



I'd set listeners for error events to make sure the file is actually being
loaded successfully.  Just copy/paste/edit from example in the livedocs 
(http://livedocs.adobe.com/flex/201/langref/flash/net/URLLoader.html
).

Dan Freiman
nondocs <http://nondocs.blogspot.com>

 On 5/23/07, *ronnlixx* <[EMAIL PROTECTED]> wrote:

I'm trying to do what i think should be pretty simple.
I want to dispatch an event when my xml has completed lodaing.
For the life of me i can't figure out why event does not get
dispatched from "handleXML", I know the listner works because I've
tested it by dispatching the same event from a button click.
Any ideas what I may be doing wrong?

package {
import flash.display.Sprite;
import com.acme.AppController;
import com.acme.MyService;

public class MyView extends Sprite
{
public function MyView()
{
var controller:MyController = new MyController(this);
}
}
}

package com.acme
{
import flash.events.EventDispatcher;
import flash.events.Event;
import flash.display.Sprite;
import com.acme.MyService;

public class MyController extends EventDispatcher
{
private var _view:Sprite;
private var _service:MyService;
public function MyController(target:Sprite){
_view = target;
_view.addEventListener("xmlLoaded", doSomething);
_service = new MyService();
}

public function doSomething(e:Event):void{
trace("doSomething CALLED");
}
}
}

package com.acme
{
import flash.events.EventDispatcher;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;

public class MyService extends EventDispatcher
{
private var _loader:URLLoader;
private var _xml:XML;

public function MyService(){
_loader = new URLLoader();
_loader.addEventListener(Event.COMPLETE, handleXML);
_loader.load(new URLRequest("xml/data.xml"));
}

public function handleXML(event:Event):void{
dispatchEvent(new Event("xmlLoaded", true)); // this never fires
_xml = new XML(_loader.data);
}
}
}






--
Teoti Graphix
http://www.teotigraphix.com

Blog - Flex2Components
http://www.flex2components.com

You can find more by solving the problem then by 'asking the question'.

Reply via email to