The following example creates a new instance of the Button component dynamically and adds it to the display list. You must first drag a copy of the component from the Component’s panel into the library.
Full code after the jump.
// ActionScript 3.0 import fl.controls.Button; var myButton:Button = new Button(); addChild(myButton);
To dynamically create a new instance of the Button class using ActionScript, you first need to drag a copy of the component from the Components panel into your current Flash document’s library. Next, you need to import the fl.controls.Button class using the import statement. This step is required since the component files are not implicitly imported, like the flash.* packages. Once the Button class has been imported into your current document, you can create a new Button instance using the new operator. Finally, the new instance can be added to the display list using the addChild() method.
To see exactly which classes get imported automatically, check out the following locations for Flash CS3 and Flash CS4:
- Flash CS3: C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\ActionScript 3.0\implicitImports.xml
- Flash CS4: C:\Program Files\Adobe\Adobe Flash CS4\Common\Configuration\ActionScript 3.0\implicitImports.xml
For more information on the implicitImports.xml file, see “Determining which classes are automatically imported in Flash CS3 and Flash CS4.
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 Creating an instance of the Button component using ActionScript 3.0 in Flash
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


Is it not possible to just drag the button out of the Component panel and start using it as in the good old days? I tried it in CS 4 and tested the movie and the movie “blinks”. I double clicked on the button and went into edit mode and saw the button had two frames, hence the blinking.
Is it possible to use the button component without Actionscript?
Wasn’t that originally why components were created..to get to use these widgets without having to do any programming??? Am I hopelessly stuck in the past?
Isn’t Flex the tool for programmers??
Help!
Thanks.