tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/574-eventdispatcher-return-null-an-a-actor-extends-classRobotlegs: Discussion 2012-07-16T08:25:55Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/160844962012-05-18T15:29:44Z2012-05-18T15:29:44ZeventDispatcher return null an a Actor Extends class<div><p>Hey karmafr,</p>
<p>Let’s start at the beginning of possible causes:</p>
<p>• Compiler arguments when linking against the rl
source:<br>
<a href=
"https://github.com/robotlegs/robotlegs-framework/wiki/Common-Problems#wiki-metadata-stripping">
https://github.com/robotlegs/robotlegs-framework/wiki/Common-Proble...</a></p>
<p>• Make sure the context doesn’t get garbage
collected:<br>
<a href=
"https://github.com/robotlegs/robotlegs-framework/wiki/Common-Problems#wiki-mysteriously-stops">
https://github.com/robotlegs/robotlegs-framework/wiki/Common-Proble...</a></p>
<p>• Make sure to override the clone() method of your custom
event class. Events can not be re-dispatched without doing so
– even non-bubbling events. It is considered best practice
when creating custom events to override clone().</p>
<p>• Where are you mapping XMLLoaderService ? In your code
snippet there is only :</p>
<p>injector.mapSingletonOf(IOrxService, LoaderOrxService);</p>
<p>After mapping XMLLoaderService, are you sure it is the same
instance of XMLLoaderService that you are trying to call?<br>
Can you show us the mapping for that XMLLoaderService and the way
you are calling the service ( from a command?)</p>
<blockquote>
<p>n.b: sorry for my custom English, my native language is
French</p>
</blockquote>
<p>Don’t worry about it:)</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/160844962012-05-18T15:40:51Z2012-05-18T15:40:51ZeventDispatcher return null an a Actor Extends class<div><p>Are you mapping the XMLLoaderService class as a singleton, or in
some other<br>
way instantiating it via Robotlegs?</p>
<p>If you're just creating it yourself (e.g. by calling "new<br>
XMLLoaderService()") then Robotlegs won't inject the
IEventDispatcher.</p>
<p>The reason I wondered is because your snippet from your context
shows this<br>
mapping:<br>
injector.mapSingletonOf(IOrxService, LoaderOrxService);</p>
<p>However, it doesn't show any mapping for the XMLLoaderService
class.</p>
<p>Paul</p></div>Paul Robertsontag:robotlegs.tenderapp.com,2009-10-18:Comment/160844962012-05-21T08:06:18Z2012-05-21T08:06:18ZeventDispatcher return null an a Actor Extends class<div><p>Hi Ondina,<br>
Many thanks to answer so quickly, infortnunatly I couldn't check
all your request until today because I didn't have access to them
on w-e.<br>
So I did the n°1 point (I forgot it)<br>
Point 2 is OK, I do the instatation of the context into a
application (see Main.mxml)<br>
Point 3 is also OK (see LoaderServiceEvent class)<br>
Point 4 and @Paul I modified my Context class (see below) but the
problem is still there, maybe I didn't well understood the mapping
concept ?</p>
<p>// <strong>Application Main.mxml</strong>:</p>
<p><?xml version="1.0" encoding="utf-8"?><br>
<s:Application xmlns:fx="<a href=
"http://ns.adobe.com/mxml/2009">http://ns.adobe.com/mxml/2009</a>"</p>
<pre>
<code> xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:views="aw.orx.views*"
creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
private var _context:MainContext;
public function showError(message:String):void
{
Alert.show(message, "Erreur");
}
protected function creationCompleteHandler(event:FlexEvent):void
{
_context = new MainContext( this );
}
]]>
</fx:Script></code>
</pre>
<p></s:Application></p>
<p>// <strong>LoaderServiceEvent class</strong>:</p>
<p>package aw.orx.models.events<br>
{</p>
<pre>
<code>import flash.events.Event;
public class LoaderServiceEvent extends Event
{
public static const LOADER_SERVICE_COMPLETED:String = "LoaderServiceCompleted";
public static const ERROR_LOADER_SERVICE:String = "errorLoaderService";
public function LoaderServiceEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
}
public override function clone():Event
{
return new LoaderServiceEvent( type );
}
}</code>
</pre>
<p>}</p>
<p>// <strong>InitializeCommand class</strong>:</p>
<p>package aw.orx.controllers.commands<br>
{</p>
<pre>
<code>import aw.orx.controllers.events.LoadWorkAreaEvent;
import aw.orx.models.services.ILoaderService;
import aw.orx.models.services.IOrxService;
import aw.orx.models.services.LoaderService;
import aw.orx.models.services.XMLLoaderService;
import aw.orx.models.vo.XmlUrlVO;
import org.robotlegs.mvcs.Command;
public class InitializeCommand extends Command
{
[Inject]
public var xmlLoaderService:ILoaderService;
[Inject]
public var _loaderService:IOrxService;
private var _menusUrls:XMLList;
private var _sectionsUrls:XMLList;
public function get menusUrls():XMLList
{
return _menusUrls;
}
public function get sectionsUrls():XMLList
{
return _sectionsUrls;
}
override public function execute() : void
{
if(_loaderService is LoaderService) {
collectUrls(_loaderService as LoaderService, "menuUrls");
}
//run();
}
public function collectUrls(loaderService:LoaderService, id:String):void
{
//_menusUrls = _loader.getXMLList("menus");
//_sectionsUrls = _loader.getXMLList("sections");
var list:XMLList = xmlLoaderService.getXMLList("menus") as XMLList;
var listArr:Vector.<XmlUrlVO>;
for each (var item:Object in list)
{
listArr.push(item as XmlUrlVO);
}
loaderService.loaderObject.menusUrls = listArr;
}
private function collectDatas():void
{
}
protected function run():void
{
dispatch(new LoadWorkAreaEvent(LoadWorkAreaEvent.LOAD_WORK_AREA));
}
}</code>
</pre>
<p>}</p>
<p>// <strong>MainContext class</strong>:</p>
<p>package<br>
{</p>
<pre>
<code>import aw.orx.controllers.commands.*;
import aw.orx.controllers.events.*;
import aw.orx.models.*;
import aw.orx.models.services.*;
...
import flash.display.DisplayObjectContainer;
import org.robotlegs.mvcs.Context;
public class MainContext extends Context
{
public function MainContext(contextView:DisplayObjectContainer=null, autoStartup:Boolean=true)
{
super(contextView, autoStartup);
}
override public function startup():void
{
//Services
injector.mapSingletonOf(IOrxService, LoaderOrxService);
//var myClassInstance:XMLLoaderService = new XMLLoaderService();
//injector.mapValue(XMLLoaderService, myClassInstance);
injector.mapSingletonOf(ILoaderService, XMLLoaderService);
//Models
...
// Controllers
...
//Views
mediatorMap.mapView(Main, MainMediator);
mediatorMap.mapView(EditionView, EditionMediator);
...
}
}</code>
</pre>
<p>}</p></div>karmafrtag:robotlegs.tenderapp.com,2009-10-18:Comment/160844962012-05-21T08:42:33Z2012-05-21T08:42:33ZeventDispatcher return null an a Actor Extends class<div><p>Hi :)<br>
I need to see the service classes as well.</p>
<p>Could you attach the entire application (as zip or fxp) ?
I’ll take a look at it.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/160844962012-05-21T08:50:35Z2012-05-21T08:50:35ZeventDispatcher return null an a Actor Extends class<div><p>OK, I've done few modification on <em>InitializeCommand
class</em></p>
<p>Thanks</p></div>karmafrtag:robotlegs.tenderapp.com,2009-10-18:Comment/160844962012-05-21T08:55:23Z2012-05-21T08:55:23ZeventDispatcher return null an a Actor Extends class<div><p>Taking a look at your app....I'll be back with answer,
hopefully;)</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/160844962012-05-21T09:13:57Z2012-05-21T09:13:57ZeventDispatcher return null an a Actor Extends class<div><p>I found the culprits:) Be right back.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/160844962012-05-21T09:23:46Z2012-05-21T09:23:46ZeventDispatcher return null an a Actor Extends class<div><p>Ok thx</p></div>karmafrtag:robotlegs.tenderapp.com,2009-10-18:Comment/160844962012-05-21T09:35:13Z2012-05-21T09:36:52ZeventDispatcher return null an a Actor Extends class<div><p>-You forgot the „implements“ statement: public class
XMLLoaderService extends Actor<br>
has to be:<br>
public class XMLLoaderService extends Actor implements
ILoaderService</p>
<p>-Your ILoaderService doesn’t contain all the methods your
are implementing in XMLLoaderService and, vice versa,
XMLLoaderService doesn’t implement all ILoaderService’s
methods.</p>
<p>-StartupCommand:</p>
<p>--You had a little typo: the loader var has to be public for the
injection to work.</p>
<p>--You have to inject the interface, since your mapping was like
this:</p>
<p>injector.mapSingletonOf(ILoaderService, XMLLoaderService);</p>
<p>--You were creating a new instance of XMLLoaderService in your
constructor. So, even if you would have mapped the service like so:
injector.mapSingleton(XMLLoaderService);</p>
<p>the loader inside of the execute() wouldn’t be the same
instance as the one injected. Don’t do anything in your
commands’ constructor.</p>
<p>public class StartupCommand extends Command<br>
{</p>
<p>[Inject] public var loader:ILoaderService;</p>
<p>//private var loader:XMLLoaderService;<=bad</p>
<p>public function StartupCommand()<br>
{</p>
<p>//loader = new XMLLoaderService;<=bad }</p>
<p>override public function execute() : void<br>
{</p>
<pre>
<code>loader.load("assets/xml/datasUrls.xml");</code>
</pre>
<p>}</p>
<p>}</p>
<p>-LoaderOrxService</p>
<p>Don’t do anything inside the class’ constructor!</p>
<p>I would need more time to investigate all the classes. But for
now, you should try to make the changes mentioned above, and in
case you encounter other problems just let us know.</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/160844962012-05-21T10:18:31Z2012-05-21T10:18:31ZeventDispatcher return null an a Actor Extends class<div><p>OK many thanks<br>
That what I thought, I figure that I still have some problems to
manage the architecture...<br>
By the way I discovered RL By reading this article :<br>
<a href=
"http://blog.jeromefath.com/2011/07/11/conception-et-developpement-dun-annuaire-flex-4-5-architecture-mvc-robotlegs-service-zend-amf-partie3/#comment-166">
http://blog.jeromefath.com/2011/07/11/conception-et-developpement-d...</a><br>
(It's in French, but I've joined the project in attach)</p>
<p>And try to do something similar, but my main dificulty is to
adapt his services classes that are made to work with Zend in
classes that work with Xml files...<br>
I did this because I have not much time, but maybe I'll choose the
wrong way and I'll better to do something more simple (without
services)</p>
<p>By the way, i've done the changes, and it fixe the main issue
(eventDispather), I still have other, especially with the
LoaderOrxService you mentionned. I think I doesn't accept my
instructions in the constructor...<br>
I will try to fix that, thanks again for your time</p></div>karmafrtag:robotlegs.tenderapp.com,2009-10-18:Comment/160844962012-05-21T11:25:20Z2012-05-21T11:25:20ZeventDispatcher return null an a Actor Extends class<div><p>You’re welcome!<br>
I’m glad you made a few steps forward :)<br>
I’ll read the article and take a look at the app, thanks for
the link.<br>
Unfortunately, I don’t have much time right now, because I
have to finish some work before going on vacation in a few days.
Your application is pretty complex, so, I can’t promise that
I’ll be able to help you with your application step by step.
I’m sure there will be others who will assist you, if need
be.</p>
<p>As for the LoaderOrxService, where are you calling it? I only
see the mapping.<br>
What is loaderObject? You’re attaching event listeners to it
or actually to functions that are implemented from the interface..?
What do you want LoaderOrxService to do? Is it actually a
service?<br>
InitializeCommand is kind of confusing ;) If xmlLoaderService and
_loaderService are both services, then it’s not a good idea
to call them both in there. One issue you might run into, is due to
the asynchronous nature of services.</p>
<p>But, as you said, maybe it’s better to find a solution
without services first, and then, later, when you’ll have
more time, to refactor the application.</p></div>Ondina D.F.