0

MXML snippet -

   <startup:MyTasks autoStart="false" >
      <startup:tasks>
         <startup:ATask id="aTask" />
         <startup:BTask id="bTask" />         
      </startup:tasks>
   </startup:MyTasks>

   <Object type="{ MyViewPM }" id="someID"/>

ATask -

   public class ATask extends Task
   {
      [Inject]
      public var viewPM : MyViewPM;
   }

MyTasks is based on http://code.google.com/p/rojored/source/detail?r=4b0a2dc267

If I leave out the 'id' of the 2 tasks (ATask, BTask), the property of these tasks dont get injected and are null.

Does parsley require ids on the objects to manage them?

Darth Ninja
  • 1,049
  • 2
  • 11
  • 34
  • I don't know but if you don't get your answer here, I suggest you post on the parsley forum, there are usually good feedbacks there – Florian F Jan 20 '11 at 08:17

1 Answers1

2

It might not be that intuitive but the MXML syntax you're using creates a MyTask object in you context and creates and array with tasks that it assigns to the property "tasks" of MyTask, not of the context itself. It might help to think of it as:

myContext.myTasks.tasks = [aTask, bTask];

When parsley introspects myContext, it will find myTasks and will process it. It won't find aTask or bTask which are nested inside the tasks array in myTasks.

In Flex MXML, when you set an id to a tag it then becomes a property of the class in which it is being instantiated---in this case, the nested ATask and BTask will become properties of the context in which you are declaring them.

So it will be more like:

myContext.myTasks.tasks = [aTask, bTask];
myContext.aTask = aTask;
myContext.bTask = bTask;

... So only then, when Parsley loops through the properties of your context, will it find the nested tasks as well and will be able to process them.

I know MyTask doesn't have that myTask id, but it doesn't need it as it is a direct property of the context (so the automatically generated property name is enough). If you were to take out TaskA and TaskB out of the MyTask definition and put them out at the same level as MyTask you'll see that the PM is properly injected into them but, of course, they won't work on the queue as you need them to.

HTH, Gabriel