【问题标题】:Can I add additional frames to button ones?我可以在按钮的框架上添加额外的框架吗?
【发布时间】:2013-11-12 15:24:18
【问题描述】:

我是 ActionScript3 和 Flash 的新手。 我会知道在按钮实例(其中有 Up、Over、Down 和 Clicked 帧,相对于 upState、overState 和 downState)中是否可以添加其他帧以使用相同的方法调用。

我需要这样的东西:

if(...){
Button.upState = Button.MyOwnFrame;
}

提前致谢!

【问题讨论】:

  • 不,我不认为你可以。

标签: actionscript-3 flash button frames simplebutton


【解决方案1】:

您可能需要查看SimpleButton 类,因为它允许您将任何DisplayObject 分配给upStateoverStatedownStatehitTestState 的不同状态。

这是来自 Adob​​e 的 API 参考的示例:

package {
    import flash.display.Sprite;

    public class SimpleButtonExample extends Sprite {
        public function SimpleButtonExample() {
            var button:CustomSimpleButton = new CustomSimpleButton();
            addChild(button);
        }
    }
}

import flash.display.DisplayObject;
import flash.display.Shape;
import flash.display.SimpleButton;

class CustomSimpleButton extends SimpleButton {
    private var upColor:uint   = 0xFFCC00;
    private var overColor:uint = 0xCCFF00;
    private var downColor:uint = 0x00CCFF;
    private var size:uint      = 80;

    public function CustomSimpleButton() {
        downState      = new ButtonDisplayState(downColor, size);
        overState      = new ButtonDisplayState(overColor, size);
        upState        = new ButtonDisplayState(upColor, size);
        hitTestState   = new ButtonDisplayState(upColor, size * 2);
        hitTestState.x = -(size / 4);
        hitTestState.y = hitTestState.x;
        useHandCursor  = true;
    }
}

class ButtonDisplayState extends Shape {
    private var bgColor:uint;
    private var size:uint;

    public function ButtonDisplayState(bgColor:uint, size:uint) {
        this.bgColor = bgColor;
        this.size    = size;
        draw();
    }

    private function draw():void {
        graphics.beginFill(bgColor);
        graphics.drawRect(0, 0, size, size);
        graphics.endFill();
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-28
    • 2016-12-16
    • 1970-01-01
    • 1970-01-01
    • 2019-12-18
    • 1970-01-01
    相关资源
    最近更新 更多