Spicefactory Forum Index Spicefactory
Forum Archive
 
 SearchSearch    Log inLog in 

dispatching message at the very begining of the app (AIR)

 
Post new topic   Reply to topic    Spicefactory Forum Index -> Spicefactory
View previous topic :: View next topic  
Author Message
Combo



Joined: 20 Feb 2013
Posts: 18

PostPosted: Wed Feb 20, 2013 9:06 pm    Post subject: dispatching message at the very begining of the app (AIR) Reply with quote

Hi,

I'm trying to dispatch a message to get a file on the computer when my app start in my main MXML file.

I initialize the context with a XML file on the preinitialize event of the app and do an handler :
Code:

protected function windowedapplication1_preinitializeHandler(event:FlexEvent):void
         {
            _context = XmlContextBuilder.build("config/config.xml", this);
            _context.addEventListener(ContextEvent.INITIALIZED, _contextInitHandler);
         }


Then, waiting for the initialized of the context :
Code:

private function _contextInitHandler(evt:ContextEvent):void
         {
            trace("dispatcher", dispatcher);
         }


But the dispatcher is null even if I declared in the public var of my main MXML file:
Code:

[MessageDispatcher]
         public var dispatcher:Function;


I know it is basic but I don't understand why.

Any idea ?

Thx.
Back to top
View user's profile Send private message
Jens Halm
Site Admin


Joined: 21 Sep 2007
Posts: 2631
Location: Cologne, Germany

PostPosted: Wed Feb 20, 2013 11:32 pm    Post subject: Reply with quote

I'd recommend to work more closely with the docs. Parsley is a rather huge framework, so even when just trying a simple hello world, it is best to understand how it is really working (or use a smaller framework instead). Your small example contains already a few mistakes or misconceptions:

1) Never try to sync Flex lifecycle events with the lifecycle of a Context or objects managed by Parsley. This is explained in more detail in chapter 9.7.5. in the manual.

2) Because of these synchronization issues it is recommended to prefer the ContextBuilder MXML tag when initializing a Parsley Context as this does more automatic synchronization under the hood than the programmatic API that you used. This means that you also usually do not need the INITIALIZED event of the Context. The ContextBuilder tag is explained in chapter 3.2 in the manual.

3) In contrast to objects you explicitly add to your MXML or XML configuration files, no MXML view is automatically managed by Parsley. I cannot give a quick example here, as there are many options, and you should really understand the differences and then pick the view wiring mechanism that suits your requirements. For view wiring I recommend to read chapter 9 which introduces the 3 main view wiring approaches.

4) In general, when you are stuck, the Troubleshooting Guide in the manual is usually a good first stop to look for answers. In your case, in chapter 16.2. (Silent Failure) it would have been right the first entry: The object is not managed.

This also means that there is no simple quick fix for your example (at least not a "good" one in the sense of recommended). I'd suggest to take a different approach based on the info above.
_________________
Jens Halm
Spicefactory
Back to top
View user's profile Send private message
Combo



Joined: 20 Feb 2013
Posts: 18

PostPosted: Thu Feb 21, 2013 12:51 am    Post subject: Reply with quote

Thx for your answer and your tips.

I'm not new in Parsley because I used it during 3 years but with Flash so I usually put my objects in XML. I'd like to use it in my Flex 4 / AIR app now Wink.

So, I switched to MXML config instead of the XML as it is written in chapter 3.2. But I'm still have trouble to use the dispatcher in the main MXML.

It works great in my components or AS3 classes which are declared in my XML or MXML config file.

Last idea : create a Group component to add to my app with a <parsley:Configure/> tag to dispatch what I want. Not very smart...

Thx for your help.
Back to top
View user's profile Send private message
Combo



Joined: 20 Feb 2013
Posts: 18

PostPosted: Thu Feb 21, 2013 1:06 am    Post subject: Reply with quote

Ok, I found my error !...

Simply declare my main MXML class in my MXML of XML config, of course...

As I did with Flash...

I love Parsley for Flash so let's go to use it with Flex ! Wink
Back to top
View user's profile Send private message
Jens Halm
Site Admin


Joined: 21 Sep 2007
Posts: 2631
Location: Cologne, Germany

PostPosted: Thu Feb 21, 2013 1:18 am    Post subject: Reply with quote

No, that does not work (if you mean declaring with an object tag), that instantiates a copy of your main class (so you end up with two instances of them, one on the stage the other not). That's why I pointed you to the view wiring chapter. In Flex views need to be treated differently and you need to pick one of the described mechanisms.
_________________
Jens Halm
Spicefactory
Back to top
View user's profile Send private message
Combo



Joined: 20 Feb 2013
Posts: 18

PostPosted: Thu Feb 21, 2013 1:26 am    Post subject: Reply with quote

Ah ?

However, if I remove my main class from the config like this :
Code:


<?xml version="1.0" encoding="utf-8"?>
<Objects
   xmlns:fx="http://ns.adobe.com/mxml/2009"
   xmlns:services="com.bookstore.services.*"
   xmlns:actions="com.bookstore.actions.*"
   xmlns="http://www.spicefactory.org/parsley"
   >
   
   <fx:Declarations>   
      <Object type="models.LibraryModel" id="libraryModel" />   
      <Object type="commands.GetLibraryCommand" />      
   </fx:Declarations>
   
</Objects>


Nothing works.

Like this :
Code:


<?xml version="1.0" encoding="utf-8"?>
<Objects
   xmlns:fx="http://ns.adobe.com/mxml/2009"
   xmlns:services="com.bookstore.services.*"
   xmlns:actions="com.bookstore.actions.*"
   xmlns="http://www.spicefactory.org/parsley"
   >
   
   <fx:Declarations>   
      <Object type="MyApp" />
      <Object type="models.LibraryModel" id="libraryModel" />   
      <Object type="commands.GetLibraryCommand" />      
   </fx:Declarations>
   
</Objects>


Everything is OK.

So what's wrong ?

Thx a lot.
Back to top
View user's profile Send private message
Jens Halm
Site Admin


Joined: 21 Sep 2007
Posts: 2631
Location: Cologne, Germany

PostPosted: Thu Feb 21, 2013 1:28 am    Post subject: Reply with quote

Please re-read my message. It's not everything ok, you manage a *copy* of your main class, *not* the one on the stage. You have to use view wiring, trust me.
_________________
Jens Halm
Spicefactory
Back to top
View user's profile Send private message
Combo



Joined: 20 Feb 2013
Posts: 18

PostPosted: Thu Feb 21, 2013 1:38 am    Post subject: Reply with quote

Ok, thank you!

Like removing my main class from the config and configuring my main view with the <parsley:Configure /> tag isn't it ? Smile

It works too, and better ! Wink
Back to top
View user's profile Send private message
Jens Halm
Site Admin


Joined: 21 Sep 2007
Posts: 2631
Location: Cologne, Germany

PostPosted: Thu Feb 21, 2013 1:42 am    Post subject: Reply with quote

That's one of the three mechanisms you can use, yes.

You can never use object tags for MXML views. With an object tag it is Parsley that instantiates the objects. However, in Flex MXML components get instantiated by Flex, so this obviously conflicts, you would always end up with Parsley managing a second instance, not the one on the stage. It's simply the way Flex works, not a deliberate choice of the Parsley creator to make your life more complicated. Smile
_________________
Jens Halm
Spicefactory
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Spicefactory Forum Index -> Spicefactory All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group