The following example shows how you can control the amount of padding between the Button instance’s icon and label by setting the textPadding style.
Full code after the jump.
Note: This example requires a symbol in the document’s library with a linkage class of AdobeLogo, as well as a Button and a Slider component.
// ActionScript 3.0 // Import the required component classes. import fl.controls.Button; import fl.controls.Slider; import fl.events.SliderEvent; /* Create a new Button component instance, set the icon style to the AdobeLogo linkage in the library, set the textPadding style to 5 pixels, and add the button to the display list. */ var myButton:Button = new Button(); myButton.label = "textPadding: 5"; myButton.setStyle("icon", AdobeLogo); myButton.setStyle("textPadding", 5); myButton.setSize(140, 40); myButton.move(10, 10); addChild(myButton); /* Create a new Slider component instance, set the liveDragging property to true, and add the slider to the display list. This slider will be used to control the amount of text padding between the button instance's icon and label text. */ var mySlider:Slider = new Slider(); mySlider.minimum = 0; mySlider.maximum = 15; mySlider.value = 5; mySlider.liveDragging = true; mySlider.tickInterval = 1; mySlider.width = myButton.width; mySlider.move(10, 60); mySlider.addEventListener(SliderEvent.CHANGE, changeHandler); addChild(mySlider); /* Handler function for the Slider component instance. This function sets the button instance's textPadding style based on the current value of the slider. */ function changeHandler(evt:SliderEvent):void { myButton.setStyle("textPadding", evt.value); myButton.label = "textPadding: " + evt.value; }
For more information on the Flash/ActionScript 3.0 Button component, see the “Using the Button component” Flash Quick Start on Adobe.com.
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

