I've made a component based on a mx:TitleWindow that contains linkbuttons that I'm using as a context-menu.
The TitleWindow component c开发者_开发技巧ontains link buttons like this:
[Bindable]
private var _showEmailThis:Boolean = false;
[Bindable]
private var _showApproveThis:Boolean = false;
[Bindable]
private var _showReviewThis:Boolean = false;
<mx:LinkButton id="lnkEmailThis"
visible="{_showEmailThis}"
includeInLayout="{_showEmailThis}"
click="lnkEmailThis_click()"
label="Email this!" />
<mx:LinkButton id="lnkApproveThis"
visible="{_showApproveThis}"
includeInLayout="{_showApproveThis}"
click="lnkApproveThis_click()"
label="Approve this!" />
<mx:LinkButton id="lnkReviewThis"
visible="{_showReviewThis}"
includeInLayout="{_showReviewThis}"
click="lnkReviewThis_click()"
label="Review this!" />
This component contains a large number of links and is re-used by multiple modules in the same application.
Within each module, this component is used when a user clicks on a row in a datagrid.
The code looks like this:
In "Requests" module:
private function dgRequests_click(event:MouseEvent):void
{
menu.showApproveThis = true;
menu.showReviewThis = true;
}
In "Performance" module:
private function dgPerformance_click(event:MouseEvent):void
{
menu.showEmailThis = true;
menu.showReviewThis = true;
}
As you can see, the visibility of individual linkbuttons is controlled within each module by setting boolean properties.
If I alter this component to use a renderer, how can I control the visibility of the linkbuttons from the code in each module (there are over a hundred links with different functionality - not every link will be used in each module)? Note: it is not known from the back-end which grid within which module uses which link. This is set in the front end within each module's actionscript file.
e.g., if the XML looks like this:
<links>
<link>
<label>Email This</label>
<visible>_showEmailThis</visible>
</link>
<link>
<label>Approve This</label>
<visible>_showApproveThis</visible>
</link>
<link>
<label>Review This</label>
<visible>_showReviewThis</visible>
</link>
</links>
and I set the Email link to show in the module like this:
private function dgPerformance_click(event:MouseEvent):void
{
menu.showEmailThis = true;
}
How do I make it take effect? Is there a way to control the visibility of a linkbutton within an item renderer in a component from the module that uses that component?
I'm not really sure I understand your question right. But if you have a component (or a group of 'em) sequentially repeating several times with different properties' values you should use mx:Repeater.
Adobe's docs on Repeater
There is also a live example in TourDeFlex (which I strongly recommend to install and use).
Looks like this is not possible.
精彩评论