im working on a Flex application and i need to update a button icon source dynamically, but, its not enough for me by changing the icon attribute to another Class variable on runtime, i need to explicitly change the Class source to another. I google my doubt but has no the answer yet.
I want something like the following:
http://www.java2s.com/Code/Flex/Graphics/ChangeImagesourceinbuttonaction.htm
But i need it to do somethig like this instead:
[Embed(source="sun.jpg")]
[Bindable]
private var dayAsset:Class;
private function init( ):void {
dayImage.source = dayAsset;
}
private function showMoon( ):void {
dayAsset.source = "moon.jpg";
}
private function showSun( ):void {
dayAsset.source = "sun.jpg";
}
I have tried the previous code without success.
Why do i need to update the “dayImage” image source this way?? Because i have the image referenced on more than one location and i need to update it all on an event triggered
Any solution 😛 or comments will be greatly appreciated.
Thanks. have a nice night.
IF I understand the question; then the answer is that you cannot change embeds at runtime. They are performed at compile time; and made part of your compiled SWF.
You most likely want to do an approach like this: