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.

Tagged with:
 

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Spam Protection by WP-SpamFree