访问event.target.incrementButton上的currentCSSState属性 [英] accessing currentCSSState property on event.target.incrementButton
问题描述
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);
$ b $ p
$ b 在特定的微调器上,我想自定义递增(0,1,3 ,5,7),所以我想知道什么时候他们推增量按钮,以知道增加值的方式
private function spinnerChange (event:Event):void
{
if(event.target.incrementButton.currentCSSState.valueOf()==down)
{
if(event.currentTarget。值== 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;
}
}
运行时出现此错误
pre $ ReferenceError:错误#1069:在spark.components.Button上找不到属性currentCSSState,并且没有默认值。
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()
flash.events::EventDispatcher/dispatchEvent()
在mx.core :: UIComponent / dispatchEvent()
在spark.components.supportClasses :: ButtonBase / commitProperties()[E:\dev\\ \\4.x\frameworks\projects\spark\src\spark\components\supportClasses\Butt onBase.as:745]
在mx.core :: UIComponent / validateProperties()
任何人都知道我可以如何使用这个属性,或者只是一个更好的方式来做这个与微调
没有这样的属性命名currentCSSState。但是, Spinner
控件具有一个 stepSize
属性,您可以使用它来控制在您的时候微调器增加/减少多少点击按钮。如果您将 stepSize
设置为2,这似乎接近您要查找的内容。
如果您想为了更好地控制微调器如何增加/减少值,可以覆盖 Spinner
控件的方法 incrementButton_buttonDownHandler()
和 decrementButton_buttonDownHandler()
,它们在您点击按钮时执行。
这是默认的这些方法:
$ b $ pre $ protected function incrementButton_buttonDownHandler(event:Event):void
{
var prevValue:Number = this.value;
changeValueByStep(true);
if(value!= prevValue)
dispatchEvent(new Event(change));
$ b您可以覆盖它以增加 this.value
,而不是调用 changeValueByStep()
方法。你可能想看看 changeValueByStep()
方法,这样你就可以看到它在做什么(它支持最小值/最大值,让值换到开始如果到达最后等等)。
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);
}
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;
}
}
I get this error when it runs
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
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.
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"));
}
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屋!