保持“低调” Spark 皮肤按钮的状态

发布于 2024-09-28 08:17:55 字数 1671 浏览 1 评论 0原文

我在按钮组件中使用了带有向上、向下、超过和禁用状态的 Spark 皮肤按钮来创建模块。有没有办法当用户按住某个键时,该按钮将保持“按下”状态?

按钮组件包含皮肤类:

<?xml version="1.0" encoding="utf-8"?>
<s:Button xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx"
    skinClass="wfm.keyBtn">
</s:Button>

Spark皮肤:

<?xml version="1.0" encoding="utf-8"?>
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx"
 <fx:Metadata>
  [HostComponent("spark.components.Button")]
 </fx:Metadata>
 <s:states>
  <s:State name="up"/>
  <s:State name="over"/>
  <s:State name="down"/>
  <s:State name="disabled"/>
 </s:states>
 <s:Rect width="18" height="80" height.down="83" radiusX="1">
  <s:stroke>
   <s:SolidColorStroke color="0xaaaaaa" weight="1"/>
  </s:stroke>
  <s:filters>
   <s:BevelFilter
    distance="0"
    angle="5" angle.down="5"
    highlightColor="0xbbbbbb" highlightColor.down="0xaaaaaa"
    highlightAlpha="1" highlightAlpha.down="1"
    shadowColor="0xaaaaaa" shadowColor.down="0xffffff"
    shadowAlpha="1" shadowAlpha.down="1"
    blurX="5" blurX.down="6"
    blurY="5" blurY.down="6"
    strength="2" strength.down="2"
    type="inner"
    />
  </s:filters>
  <s:fill>
   <s:LinearGradient rotation="90">
    <s:GradientEntry color="0xf3f3f3" color.down="0xfff963" />
   </s:LinearGradient>
  </s:fill>
 </s:Rect>
</s:SparkSkin>

I have spark skin a button with up, down, over, and disable states in a button component to create a modular. Is there a way when the user press and hold a key, the button will remain in 'down' state?

The button component include skinclass:

<?xml version="1.0" encoding="utf-8"?>
<s:Button xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx"
    skinClass="wfm.keyBtn">
</s:Button>

Spark skin:

<?xml version="1.0" encoding="utf-8"?>
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx"
 <fx:Metadata>
  [HostComponent("spark.components.Button")]
 </fx:Metadata>
 <s:states>
  <s:State name="up"/>
  <s:State name="over"/>
  <s:State name="down"/>
  <s:State name="disabled"/>
 </s:states>
 <s:Rect width="18" height="80" height.down="83" radiusX="1">
  <s:stroke>
   <s:SolidColorStroke color="0xaaaaaa" weight="1"/>
  </s:stroke>
  <s:filters>
   <s:BevelFilter
    distance="0"
    angle="5" angle.down="5"
    highlightColor="0xbbbbbb" highlightColor.down="0xaaaaaa"
    highlightAlpha="1" highlightAlpha.down="1"
    shadowColor="0xaaaaaa" shadowColor.down="0xffffff"
    shadowAlpha="1" shadowAlpha.down="1"
    blurX="5" blurX.down="6"
    blurY="5" blurY.down="6"
    strength="2" strength.down="2"
    type="inner"
    />
  </s:filters>
  <s:fill>
   <s:LinearGradient rotation="90">
    <s:GradientEntry color="0xf3f3f3" color.down="0xfff963" />
   </s:LinearGradient>
  </s:fill>
 </s:Rect>
</s:SparkSkin>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疯到世界奔溃 2024-10-05 08:17:55

创建 Button 的子类,并告诉皮肤在您关心的键按下时处于按下状态。另外,每当您检测到按键按下(或不再按下)时,使皮肤状态无效,以便皮肤知道检查它应该处于什么状态:

package mypackage
{
    import spark.components.Button;

    public class MyButton extends Button
    {
        private var _isKeyDown:Boolean = false;

        private function get isKeyDown():Boolean {
            return _isKeyDown;
        }

        private function set isKeyDown(b:Boolean):void {
            _isKeyDown = b;
            this.invalidateSkinState();
        }

        // Add handlers in here to set isKeyDown to true/false appropriately

        override protected function getCurrentSkinState():String {
            if (isKeyDown)
                return "down";
            else
                return super.getCurrentSkinState();
        }
    }
}

Create a subclass of Button and tell the skin to be in the down state whenever the key you care about is down. Also, whenever you detect the key is down (or no longer down), invalidate the skin state so the skin knows to check what state it should be in:

package mypackage
{
    import spark.components.Button;

    public class MyButton extends Button
    {
        private var _isKeyDown:Boolean = false;

        private function get isKeyDown():Boolean {
            return _isKeyDown;
        }

        private function set isKeyDown(b:Boolean):void {
            _isKeyDown = b;
            this.invalidateSkinState();
        }

        // Add handlers in here to set isKeyDown to true/false appropriately

        override protected function getCurrentSkinState():String {
            if (isKeyDown)
                return "down";
            else
                return super.getCurrentSkinState();
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文