问题
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
回答1:
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.).
来源:https://stackoverflow.com/questions/13975457/accessing-currentcssstate-property-on-event-target-incrementbutton