Question

I am creating a sample MVC using Parsley Framework of Flex. I am having one slider control (mx:HSlider) which dispatches the event to the model for doing something on slider change. For that i have created one custom event and i am using parsley selectors for handling event. Here is the code

//Event
        class MyEvent extends Event
        {
        public static const MSG="msg";
    //constructor, clone method and two fields
        }

//View
    <fx:Metadata>
    [Event name="msg" type="pack1.MyEvent"]
    [ManagedEvents("msg")]
    </fx:Metadata>

    <fx:Declaration>
    <parsley:Configure/>
    </fx:Declaration>

    public function onSliderChange(event:SliderEvent):void
    {
    dispatchEvent(new MyEvent(MyEvent.MSG,event.thumbIndex,event.value);
    }

//Model
    [MessageHandler(selector="msg")]
    public function doSomething(event:MyEvent)
    {
    //code
    }

Now, event gets dispatched successfully but somehow message handler is not getting called. What can be wrong here? Can anyone please make me know what is problem? Any kind of help will be appreciated. Thanks in advance.

Note : My context is getting initialized and my model is also getting injected. But the events shows me some strange behaviour. It is just not getting dispatched to the model where handlers for that are.

Was it helpful?

Solution 3

I thought there is an error in some configuration or in normal events with parsley events but in my code i was dispatching more that one events from the class and i was writing them as

[ManagedEvents("a","b","c")]

But after reading documentation of parsley i observed that it should be

[ManagedEvents("a,b,c")]

It solved my problem. Thanks for all your replies.

OTHER TIPS

try this:

[MessageHandler(selector="msg")]

you've missed a closing bracket.

In a view class, Parsley does not automatically "manage" the view. Views are typically not added to the Parsley context (unless you specifically add them to the context). Because views can come and go, you don't want Parsley to manage them by default like you would with controllers, dynamic commands, models, etc.

To get Parsley to manage a view, and therefore recognize that it needs to invoke your message handler, you need to add a Parsley <Configure /> tag to the view. This makes the view dispatch an event with the type "configureView". Before this tag existed, you would manually dispatch this event when the view is added to the stage.

Do something like this in your view:

<fx:Declarations>
    <parsley:Configure />
</fx:Declarations>

(In a Flex 3 app, you'd just add the <Configure /> tag to the view, that is, you wouldn't put it inside a declaration tag. You can read about it in the Parsley docs.

You have to add the view to the context. that is the only missing part.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top