Skip to main content

Dynamically changing the background color in Adobe Flex Builder

Recently I have been messing around a bit with Flex 3.0. In one particular occasion I was wondering what would be the easiest way to let a user change the background of a Flex based website. The project consisted of just a standard color picker component (just to illustrate the point). Basically what you want to do is capture the selected color when a particular event is being fired, and use this information to dynamically change the background color of the Flex application.

So, in your main MXML document you can add a standard ColorPicker component, give it an x, y coordinate to put it someplace near the center, and on the "close" event of this component you would use the setStyle() method of the UIComponent class. The code to do this is listed here below:

<mx:ColorPicker id="color" x="380" y="338" 
close="{this.setStyle('backgroundGradientColors', 
[color.selectedColor,color.selectedColor])}" />

Can it be done more easily? I guess not.

Comments

Popular posts from this blog

But Google what about mobile phones that do not support Javascript?

In the global device market, there are still between 0.2% and 5.4% of phones that do not support Javascript, at least in these set of countries according to this site. In case your mobile website falls within this set than what do you do when you want to optimize CSS delivery by deferring the loading of some CSS but still serving the complete CSS to non-Javascript websites?

A Short Online Letter to the Board of Alphabet Inc.

Dear Chairman Hennessy, I would like to openly share a question that kept coming back to me in the past couple of days, and that gave me courage to write a short open letter for the first time in my life. While catching up with daily news I came across a couple of articles in the past week alone, namely on the world’s remaining wilderness areas that are under threat . That the Earth’s oceans have retained 60 percent more heat each year than we’ve previously thought, that humanity has wiped out 60% of animal populations since 1970, that China has legalised rhino horn and tiger bone usage after 25 years, to calling for urgent action to develop technologies for negative emissions because our clean energy efforts won’t be enough. Here’s the question: is there actually a future for us, for your company, for humanity and our natural environment? What we do today will lay down the trajectory for our carrying capacity on Earth. Instead of investing in self-driving transportation and