开发者

Custom skin Button in Flash CS5

开发者 https://www.devze.com 2023-03-25 23:07 出处:网络
Morning all I don\'t know why this isn\'t simpler to achieve! Here we go: In my pure Flash CS5 AS3 project, I need to make some Buttons. Many different sorts of Buttons, which have different sets of

Morning all

I don't know why this isn't simpler to achieve! Here we go:

In my pure Flash CS5 AS3 project, I need to make some Buttons. Many different sorts of Buttons, which have different sets of skins. Completely different.

So, taking the Button component and changing the skins in the Symbol is not good enough, because that changes all Buttons. And I need lots of different ones.

We all know how to re-skin the core Button component, which has the effect of altering all buttons.

Does开发者_StackOverflow中文版 anyone know how to make discrete customisations of Button, or something to similar effect?

Cheers

Rich


Not 100% sure what you mean.. If you need to have multiple different buttons why can't you just create multiple buttons using the Convert to symbol feature from the context menu when selecting objects in the UI?

If you need to maintain some type of functionality across these buttons, then I can recommend encapsulating all of this into a class that has a property skin:SimpleButton. What you can do here is have a setter for skin that applies your event listeners or whatever like this:

public function set skin(btn:SimpleButton):void
{
    btn.addEventListener(MouseEvent.CLICK, _someFunc);
}

All you'll really need to do then is either create some classes for each of your different buttons that specify the skin to use in the constructor:

public function SomeButton()
{
    skin = new MyLibraryButton();
}

Or do it on the fly:

var button:MyButton = new MyButton();
button.skin = new MyLibraryButton();

Is this what you were after?


Here is a more complete example of what I am describing above:

package
{
    import flash.display.SimpleButton;
    import flash.events.MouseEvent;

    public class MyButton extends Object
    {
        // Properties
        private var _skin:SimpleButton;

        /**
         * Defines the button skin to use
         * @param btn Reference to an instance of SimpleButton
         */
        public function set skin(btn:SimpleButton):void
        {
            _skin = btn;

            btn.addEventListener(MouseEvent.CLICK, _click);
        }

        /**
         * Called when the skin (button) has been clicked
         * @param e MouseEvent.CLICK
         */
        private function _click(e:MouseEvent):void
        {
            trace("Button was clicked");
        }

        /**
         * Getters
         */
        public function get skin():SimpleButton{ return _skin; }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号