In my example below I have several objects. I want to change the label of all objects in one go, without calling each element by id. I know how to do this in HTML, but not in Flex.
// HTML
<div class="text" id="text1">SomeText</div>
<div class="text" id="text2">SomeText</div>
<div class="text" id="text3">SomeText</div>
// jQuery
$(".text").css("color", "#333333");
This is how I would usually set the color of 3 objects to grey in one line.
// Flex
<s:Button id="button1" label="Button 1"/>
<s:Button id="button2" label="Button 2"/>
<s:Button id="button3" label="Button 3"/>
// AS3
button1.label = 'Something else';
button2.label = 'Something else';
button3.label = 'Something else';
Is there any way I can change the labels of all 3 buttons with a single line of code similar to the jQuery example? Thanks in advance.
As @www.Flextras.com pointed out – you can write a class to do this.
I’d encourage you to consider an alternative approach however, as looping through the children looking for a specific property is quite slow. That said – it does make for an interesting coding challenge.
Here’s a class & example that should acheive what you’re after.
And an example:
Note – I haven’t tested this, but in theory it should work.