The following example demonstrates how to load a remote image for a button icon using both a Loader instance and a UILoader component instance.
Full code after the jump.
// ActionScript 3.0 // Import the required component classes. import fl.controls.Button; import fl.containers.UILoader; // Create a new Loader instance, and load an external PNG image. var logo:Loader = new Loader(); logo.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler1); logo.load(new URLRequest("http://www.helpexamples.com/flash/images/logo.png")); // Create a new UILoader component instance and load an external PNG image. var logo2:UILoader = new UILoader(); logo2.scaleContent = false; logo2.addEventListener(Event.COMPLETE, completeHandler2); logo2.load(new URLRequest("http://www.helpexamples.com/flash/images/logo.png")); // Create a new Button component instance, and add it to the display list. var myButton:Button = new Button(); myButton.label = "Loader"; myButton.move(10, 10); myButton.setSize(140, 100); addChild(myButton); /* Create a new Button component instance, and add it to the display list. */ var secondButton:Button = new Button(); secondButton.label = "UILoader"; secondButton.move(160, 10); secondButton.setSize(140, 100) addChild(secondButton); /* Handler function for the Loader instance. This function sets the icon style for the myButton button instance, and updates the button's display using the validateNow() method. */ function completeHandler1(evt:Event):void { myButton.setStyle("icon", logo); myButton.validateNow(); } /* Handler function for the UILoader component instance. This function sets the icon style on the secondButton button instance, and updates the UILoader and Button components display using the validateNow() method. */ function completeHandler2(evt:Event):void { secondButton.setStyle("icon", logo2); logo2.validateNow(); secondButton.validateNow(); }
For more information on the Flash/ActionScript 3.0 Button component, see the “Using the Button component” Flash Quick Start on Adobe.com.
One Response to Using an external image for a Button icon in Flash with ActionScript 3.0
Leave a Reply Cancel reply
Recent Posts
- Getting started with the TLFTextField class in ActionScript 3.0 and Flash CS5
- Adding tick marks to a Slider control in Flash using ActionScript 3.0
- Creating a vertical Slider control in Flash using ActionScript 3.0
- Creating a custom context menu item in Flash using ActionScript 3.0
- Rotating a Sprite object around its x-axis in Flash using ActionScript 3.0 and Flash Player 10
- Detecting when the user changes the color in a ColorPicker control in Flash using ActionScript 3.0
- Getting the currently selected color as a hexadecimal value on a ColorPicker control in Flash using ActionScript 3.0
- Toggling the text field on the ColorPicker control in Flash using ActionScript 3.0
- Creating a vertical Slider control in Flash using ActionScript 3.0
- Setting the number of columns on a ColorPicker control in Flash using ActionScript 3.0
Categories
- Bitmap (1)
- Components (72)
- Button (19)
- CheckBox (2)
- ColorPicker (6)
- ComboBox (1)
- DataGrid (8)
- FLVPlayback (7)
- Label (9)
- ProgressBar (2)
- Slider (3)
- TextArea (1)
- TextInput (7)
- UILoader (7)
- ContextMenu (1)
- Embed (4)
- ExternalInterface (2)
- Flex (7)
- Font (2)
- General (5)
- Graphics (2)
- JSFL (14)
- Loader (3)
- LoadVars (3)
- Microphone (1)
- migration (12)
- MovieClip (1)
- MovieClipLoader (1)
- Sound (2)
- TextField (1)
- TLFTextField (1)
- TransitionManager (1)
- Tween (1)
- Uncategorized (1)
- URLLoader (4)
- URLVariables (1)
- Video (1)
- XML (2)
Advertising
" RT @OReillyMedia: #Ebook Deal/Day: Learning JavaScript Design Patterns -
$11.99
(Save 50%)
http://t.co/ilcmSDv6 " — pdehaan


in my web site, im willing to add a button called ädd icon”. (just to add some icons)
can any of you please tell me the way to do it by using flash actionscripts?