Link to home
Create AccountLog in
Avatar of Jay Roy
Jay RoyFlag for United States of America

asked on

passing label value on view click

hi guys
I am tring to pass a label from outer mxml to inner mxml

I have a view stack like this
<mx:ViewStack id="workflowViewStack" width="100%" borderColor="#000000" cornerRadius="4" selectedIndex="{modelviewdata.workflowviewstate}">              
<workflowNavigation:WorkflowView label="{(modelviewdata.doesWorkflowExist == false ? 'Create New Profile' : (modelviewdata.showWorkFlow == true ? modelviewdata.selectedWorkflowid : ''))}" height="3000" width="3000"  />
</mx:ViewStack>      

this is my WorkflowView.mxml. When WorkflowView is clicked i want to invoke the init() function and pass the label value to it.

WorkflowView.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
 xmlns:viewStackEffects="org.efflex.mx.viewStackEffects.*"  
 borderStyle="none" height="2000" xmlns:buttons="com.ms.ewq.view.component.buttons.*"
creationComplete="init()">
..
<mx:Script>
             
<![CDATA[
private function init():void {
here i want to pass the lable value to  WorkflowSearchEvent
mx.controls.Alert.show("label",label);
var workflowevent:WorkflowSearchEvent = new WorkflowSearchEvent(label);
workflowevent.dispatch();
}

any idea?
thanks
Avatar of dgofman
dgofman
Flag of United States of America image

Implementation is not the best and wrong

You should dispatch from child an event

http://livedocs.adobe.com/flex/3/html/help.html?content=mxmlcomponents_advanced_4.html

this.dispatchEvent(workflowevent);

By before add a metadata in your MXML for handle this event from outside

Lets believe you have class com.mycompany.events.WorkflowSearchEvent
And event type is “searchEvent
In this case client MXML declaration will be
<mx:Metadata>
    [Event(name=" searchEvent ", type="com.mycompany.events.WorkflowSearchEvent ")]
</mx:Metadata>

Now you can handle this event from a parent class

<workflowNavigation:WorkflowView searchEvent=”onSearchEvent(event) "  ..

Private var onSearchEvent(event: WorkflowSearchEvent):void{

By before add a metadata in your MXML for handle this event from outside

Lets beleive you have class com.mycompany.events.WorkflowSearchEvent
<mx:Metadata>
    [Event(name="eventName", type="eventType")]
</mx:Metadata>
Another option you can call the parent class function and pass label

parentDocument.setLabel(label);

You just need to implement "public function setLabel(value:String):void" in your parent class
Avatar of Jay Roy

ASKER

hi
i am trying to understand your code, here are the changes i made
in my parent i added
parent.mxml

public function onSearchEvent(event: WorkflowSearchEvent):void{
var workflowevent:WorkflowSearchEvent = new WorkflowSearchEvent(this.label);
workflowevent.dispatch();
}
<workflowNavigation:WorkflowView label="{(modelviewdata.doesWorkflowExist == false ? 'Create New Profile' : (modelviewdata.showWorkFlow == true ? modelviewdata.selectedWorkflowid : ''))}"
height="3000" width="3000" searchEvent="onSearchEvent(event)" />

In WorkflowView.mxml i added
<mx:Metadata>
[Event(name="searchEvent", type="com.ms.ewq.Events.Workflow.WorkflowSearchEvent")]
</mx:Metadata>


am i correct?
thanks
ASKER CERTIFIED SOLUTION
Avatar of dgofman
dgofman
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Jay Roy

ASKER

hi...
what is meant by this>>>workflowevent.label = "My Label";

what should My Label be?

thanks