Jay Roy
asked on
removing redundancy in mxml
hi guys
I am new to flex so not sure how to solve this
I have 2 mxml files, both the mxml files have a peice of code which is repeated.
I want to avoid that. My 2 mxml are
1.developer.mxml
2.manager.mxml which contains the same code just to check the role of manager.
ent) in two places to get the user object. My goal is to have the code only once and reuse it.
Is that possible?
thanks
I am new to flex so not sure how to solve this
I have 2 mxml files, both the mxml files have a peice of code which is repeated.
I want to avoid that. My 2 mxml are
1.developer.mxml
<mx:Script>
<![CDATA[
[Bindable]
private var user:Object;
private function userHandler(event:ResultEvent):void
{
user = event.result;
}
]]>
</mx:Script>
<mx:RemoteObject id="secHelper" destination="secHelper" >
<mx:method name="getAuthCredentials" result="userHandler(event)"/>
</mx:RemoteObject>
<mx:HBox width="100%" visible="{user.authority.contans(DEVELOPER)}" > //using the user object here to check the role
<mx:Button label="New Project Developer"/> //button differs based on role
</mx:HBox>
now i have another mxml2.manager.mxml which contains the same code just to check the role of manager.
<mx:Script>
<![CDATA[
[Bindable]
private var user:Object;
private function userHandler(event:ResultEvent):void
{
user = event.result;
}
]]>
</mx:Script>
<mx:RemoteObject id="secHelper" destination="secHelper" >
<mx:method name="getAuthCredentials" result="userHandler(event)"/>
</mx:RemoteObject>
<mx:HBox width="100%" visible="{user.authority.contans(MANAGER)}" > //using the user object here to check the role
<mx:Button label="New Project Manager"/> //button differs based on role
</mx:HBox>
So clearly there is redundancy. I am repeating the <mx:RemoteObject> and function userHandler(event:ResultEvIs that possible?
thanks
ASKER
>>>Hope this makes sense.
can you provide some code? i am new to flex and still learning it so i cant understand 100% of what you said but i get the point. Some code would help.
thanks.
can you provide some code? i am new to flex and still learning it so i cant understand 100% of what you said but i get the point. Some code would help.
thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Create a Service mxml and place the Remote Object tag there as you have done here. Then place the handlers and dispatch custom events with the results.
Now in your developer and manager mxml add the service mxml like any other component and execute it by calling its public APIs that you need to declare in the Service mxml.
Hope this makes sense.
Warm Regards
Deepanjan Das