访问 event.target.incrementButton 上的 currentCSSState 属性 [英] accessing currentCSSState property on event.target.incrementButton

查看:20
本文介绍了访问 event.target.incrementButton 上的 currentCSSState 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在创建一个这样的微调器

I am currently creating a spinner like this

                    var scoreSpinner:Spinner = new Spinner();
                scoreSpinner.width = 25;
                scoreSpinner.value = scoreList.getItemAt(index).Score;
                scoreSpinner.minimum = scoreList.getItemAt(index).Minimum;
                scoreSpinner.maximum = scoreList.getItemAt(index).Maximum;
                scoreSpinner.snapInterval = 1;//scoreList.getItemAt(index).Increment;

                if(scoreNameLabel.text == "Disconnect Impact")
                {
                    scoreSpinner.addEventListener(Event.CHANGE, spinnerChange);
                }

在特定的微调器上,我想进行自定义递增(0、1、3、5、7),因此我想知道他们何时按下递增按钮以了解递增值的方式

On a specific spinner I want to do custom incrementing (0, 1, 3, 5, 7) so I want to know when they push increment button to know which way to increment the value

            private function spinnerChange(event:Event):void
        {
             if(event.target.incrementButton.currentCSSState.valueOf() == "down")
            {
                if(event.currentTarget.value == 2)
                    event.currentTarget.value = 3;

                if(event.currentTarget.value == 4)
                    event.currentTarget.value = 5;

                if(event.currentTarget.value == 6)
                    event.currentTarget.value = 7;
            }

            if(event.target.incrementButton.currentCSSState.valueOf() == "up")
            {
                if(event.currentTarget.value == 2)
                    event.currentTarget.value = 1;

                if(event.currentTarget.value == 4)
                    event.currentTarget.value = 3;

                if(event.currentTarget.value == 6)
                    event.currentTarget.value = 5;
            } 

        }

运行时出现这个错误

ReferenceError: Error #1069: Property currentCSSState not found on spark.components.Button and there is no default value.
at lcmp.web.wsc.ui.shared.controls.PreWSC.ProgramScore::ProgramScore/spinnerChange()[C:\TFS\Release Branches\CR13\Flex\Web\WSC\src\lcmp\web\wsc\ui\shared\controls\PreWSC\ProgramScore\ProgramScore.mxml:298]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()
at spark.components::Spinner/decrementButton_buttonDownHandler()[E:\dev\4.x\frameworks\projects\spark\src\spark\components\Spinner.as:455]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()
at spark.components.supportClasses::ButtonBase/commitProperties()[E:\dev\4.x\frameworks\projects\spark\src\spark\components\supportClasses\ButtonBase.as:745]
at mx.core::UIComponent/validateProperties()

任何人都知道我可以如何使用此属性或使用微调器更好地执行此操作

anyone know how I can use this property or just a better way of doing this with a spinner

推荐答案

没有名为currentCSSState"的属性.但是,Spinner 控件有一个 stepSize 属性,您可以使用该属性控制单击按钮时微调器的递增/递减量.如果您将 stepSize 设置为 2,这似乎与您要寻找的很接近.

There is no such property named "currentCSSState". However, the Spinner control has a stepSize property you can use which controls how much the spinner is incremented/decremented when you click the button. If you set the stepSize to 2, this seems close to what you're looking for.

如果您想更多地控制微调器如何增加/减少值,您可以覆盖 Spinner 控件的方法 incrementButton_buttonDownHandler()decrementButton_buttonDownHandler(),点击按钮时执行.

If you want to have more control of how the spinner increments/decrements the value, you can override the Spinner control's methods incrementButton_buttonDownHandler() and decrementButton_buttonDownHandler(), which are executed when you click the buttons.

以下是其中一种方法的默认实现:

Here is the default implementation of one of these methods:

protected function incrementButton_buttonDownHandler(event:Event):void
{
    var prevValue:Number = this.value;
    changeValueByStep(true);
    if (value != prevValue)
        dispatchEvent(new Event("change"));
}

您可以覆盖它以根据自己的喜好增加 this.value 而不是调用 changeValueByStep() 方法.你可能想看看 changeValueByStep() 方法,这样你就可以看到它在做什么(它尊重最小值/最大值,如果你到达结尾,让值回到开头,等).

You can override this to increment this.value to your liking rather than calling the changeValueByStep() method. You might want to take a look at that changeValueByStep() method so you can see what it is doing (it honors the min/max values, lets the value wrap to the beginning if you reach the end, etc.).

这篇关于访问 event.target.incrementButton 上的 currentCSSState 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆