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 881171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:13:03+00:00 2026-05-15T12:13:03+00:00

What I have is a class with static properties that I want to use

  • 0

What I have is a class with static properties that I want to use as images. I would like the images to be configurable at run time but still have the defaults. So the Images class looks like:

package {
public class Images {

[Embed(source="/assets/Green-Light.gif")]
[Bindable]
public static var GreenLight:Class;
}
}

And now a custom component:

package {
import mx.binding.utils.BindingUtils;
import mx.controls.Image;

import spark.components.HGroup;

public class MyComp extends HGroup {
    private var _image:Image;

    public function MyComp() {
        _image = new Image();
        _image.source = Images.GreenLight;
        addElement(_image);
        BindingUtils.bindSetter(setImageIcon, Images, "GreenLight");
    }

    private function setImageIcon(newIcon:Class):void {
        trace(newIcon);
        _image.source = newIcon;
    }
}
}

Now if I create an application like this:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark"
           xmlns:mx="library://ns.adobe.com/flex/mx"
           minWidth="955"
           minHeight="600"
           xmlns:ns1="*">
<fx:Script>
    <![CDATA[
        [Embed(source="/assets/Yellow-Light.gif")]
        [Bindable]
        public var YellowLight:Class;
    ]]>
</fx:Script>
<mx:Image source="{Images.GreenLight}"/>
<s:Button x="10"
          y="40"
          label="Button"
          click="Images.GreenLight=YellowLight"/>
<ns1:MyComp x="40" y="0"/>
</s:Application>

Clicking the button will change the static property in the Images class to something else. The image defined in the MXML will get the binding event and update the image, but the custom component created in ActionSctipt will not be updated.

My question is why? and how do I fix it?

Thanks!

  • 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-15T12:13:04+00:00Added an answer on May 15, 2026 at 12:13 pm

    From the looks of the generated code it’s not worth trying to figure out how AS is doing it’s magic. In that case the best (easiest) option is just to turn the Images class into a Singleton like this:

    package   {
    
    public class Images {
        private static var _self:Images;
        public static function getInstance():Images {
            if(_self == null) {
                _self = new Images();
            }
            return _self;
        }
        [Embed(source="/assets/Green-Light.gif")]
        [Bindable]
        public var GreenLight:Class;
    }
    }
    

    And the MyComp class will do the binding like:

    BindingUtils.bindSetter(setImageIcon, Images.getInstance(), "GreenLight");
    

    Thanks to Maxim for the advice.

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

Sidebar

Related Questions

I have a static class that looks like this: namespace Argus { static class
I have a static class which only contains string properties. I want to convert
I have an interface based class that I want to have a few static
I have class A such that: class A { static int i; A(); f1();
I have a static class in a shared project, which I want to extend
I have a static class with no static constructor, but many static members. I
I have a Car class with various properties. I have a static Cars collection
Suppose that I have two classes, first a class without any properties, fields or
I have a model that looks something like this: public class SampleModel { public
I have a class that has a complex static factory method, lets call it

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.