You're probably looking for
this["copper"]
Gordon Smith
Adobe Flex SDK Team
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of celumbra
Sent: Monday, May 12, 2008 2:00 PM
To: [email protected]
Subject: [flexcoders] how to lookup a component with only a string id
I am looking for how to access components when all I have is its id
string.
In one experiment, shown below, for instance, I have a repeater to build
a set of buttons
from an array collection. When clicked, I want to select a particular
component in the
application. If I pass the id of the component in the arrayCollection, I
get a reference of
null, though I notice that in a regular array, I can pass the id and use
it throughout the
application.
Is there some way to access the particular component with only a string
reference for its
id-something like Application.application.component.id? Or must I run
two arrays, using
the index of the button clicked from the repeater, and using that index
to select from
another array of containers (e.g. containers = [copper, purple, red,
magenta, gold]. Or am I
on the right track below, but need to structure the original array
differently, so that it can
hold a pointer to the component? Or must I code the reference values
inside a custom
button and, during the repetition, use the event.target to collect those
values from the
custom component to use in the eventhandler.getRepeaterItem() method?
I am not sure what header subject to look under to answer these
questions. I am pretty
sure I can simply test the string and, in a switch statment, get to the
container, but I
would like to understand what the possible tools are and under which
heading to search to
study more about it. Any help would be greatly appreciated.
Here is some sample code to illustrate the issue.
//array of objects not bindable? //the component id is the container key
` [Bindable]
public var feedToButtonRepeater:Array = [{label: "copper", container:
copper,
level1Security: true, level2Security: "dubaiLand"},
{label: "purple", container: purple, level1Security: false,
level2Security: "universalStudios"},
{label: "red", container: red, level1Security: true,
level2Security: "disneyland"},
{label: "magenta", container: magenta, level1Security: false,
level2Security: "sixflags"},
{label: "gold", container: gold, level1Security: true,
level2Security: "junctioncity"}];
<mx:ArrayCollection id= "buttonSetUp" source="{feedToButtonRepeater}"/>
//example UIComponent
<mx:Canvas id="copper" width="50" height="50" x="0"
backgroundColor="{Color.COPPER_3}">
<mx:Label text="copper"/>
</mx:Canvas>
//Repeater
<mx:VBox id="level3InnerContainer" x="159" horizontalAlign="center"
verticalScrollPolicy="off" horizontalScrollPolicy="off" y="140">
<mx:Repeater id="myrep" dataProvider="{buttonSetUp}">
<mx:Button styleName="mainNavButton" blendMode="{BlendMode.ADD}"
label="{myrep.currentItem.label}" height="30" width="100"
click="repeaterClickHandler(event.currentTarget.getRepeaterItem());"/>
</mx:Repeater>
</mx:VBox>
//repeater event handler
private function repeaterClickHandler(obj:Object):void
{
obj.container.visible = true; //obj.container is null, but obj.label =
"copper" and
obj.level1Security = true.
}