Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1052017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:01:32+00:00 2026-05-16T17:01:32+00:00

In my example below I have several objects. I want to change the label

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:01:32+00:00Added an answer on May 16, 2026 at 5:01 pm

    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.

    package com.mangofactory.util
    {
        import flash.display.DisplayObject;
    
        import mx.core.UIComponent;
    
        /**
         * Utility class to set a given property of all matching children on a target.
         * Named to act as an operator, rather than a class (hence no captial letter)
         *
         * eg.,  on(someTarget).of(SomeClass).someProperty = someValue;
         * */
        public class on
        {
            private var root:UIComponent;
            private var requiredPropertyName:String;
            private var requiredType:Class;
    
            public function on(root:UIComponent)
            {
                this.root = root;
            }
            /**
             * Returns a list of targets which match the defined criteria.
             * Note - the root component is also evaluated
             * */
            private function get targets():void
            {
                var result:Array = [];
                if (matches(root))
                {
                    result.push(root);
                }
                for (var i:int = 0; i < root.numChildren; i++)
                {
                    var child:DisplayObject = root.getChildAt(i);
                    if (matches(child))
                        result.push(child);
                }
            }
            /**
             * Returns true if the target param matches the defined criteria.
             * If a propertyName has been given (by calling 'having') that is checked first.
             * Otherwise, the type is checked against the value passed calling ('of')
             * */
            private function matches(target:Object):Boolean
            {
                if (requiredPropertyName && target.hasOwnProperty(requiredPropertyName))
                    return true;
                if (requiredType && target is requiredType)
                    return true;
                return false;
    
            }
            public function having(propertyName:String):PropertyCatcher
            {
                this.requiredPropertyName = propertyName;
            }
            public function setOnTargets(propertyName:*,value:*):void
            {
                for each (var matchedTarget:Object in targets)
                {
                    if (matchedTarget.hasOwnProperty(propertyName))
                        matchedTarget[propertyName] = value;
                }
            }
            public function of(type:Class):PropertyCatcher
            {
                this.requiredType = type;
            }
        }
    }
    import com.mangofactory.util.on;
    
    import flash.utils.Proxy;
    import flash.utils.flash_proxy;
    use namespace flash_proxy;
    
    dynamic class PropertyCatcher() extends Proxy
    {
        private var callbackTarget:on;
        public function PropertyCatcher(callbackTarget:on)
        {
            this.callbackTarget = callbackTarget;
        }
        override flash_proxy function setProperty(name:*, value:*):void {
            callbackTarget.setOnTargets(name,value);
        }
    }
    

    And an example:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx">
        <s:Button />
        <s:Button />
        <s:Button />
        <mx:Canvas  />
        <fx:Script>
            <![CDATA[
                public function doTest():void
                {
                    // Sets the label of all Buttons to "Hello World" 
                    on(this).of(Button).label = "Hello World";
                    // Sets the visible property of all children which declare a "alpha" property to false.
                    on(this).having("alpha").visible = false;
                }
            ]]>
        </fx:Script>
    </mx:Canvas>
    

    Note – I haven’t tested this, but in theory it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the example below I have a ListBox with dozens of font names in
How can I select the good method (I have in the example below show
Below I have a very simple example of what I'm trying to do. I
I have example of code below. <script type=text/javascript src=assets/scripts/somescript.php>. </script> So, will my browser
I know there are several similar questions on SO, I have used some of
I have an array of 1000 or so entries, with examples below: wickedweather liquidweather
I have a few tables that I've defined like the below examples: class TableA
The example below throws an InvalidOperationException, Collection was modified; enumeration operation may not execute.
In my example below I'm using a dijit.form.DateTextBox : <input type=text name=startDate dojoType=dijit.form.DateTextBox constraints={datePattern:'MM/dd/yyyy'}
I usually do something like the example below when I need to return error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.