开发者

Using HSlider: coercion of Event to SliderEvent

Porting 开发者_高级运维a pure Flash/AS3 application to Flex 4.5 this code:

<fx:Script>
    <![CDATA[
        import mx.events.SliderEvent;
        import flash.filters.ColorMatrixFilter;

        private function handleSlider(event:SliderEvent):void { 
            var hide:Number = event.value;
            _settings.data.hide = hide;
            _settings.flush();

            if (hide >= 0.8) {
                filters = null;
            } else {
                var matrix:Array = new Array();
                matrix = matrix.concat([1, 0, 0, 0, 1]);    // red
                matrix = matrix.concat([0, 1, 0, 0, 1]);    // green
                matrix = matrix.concat([0, 0, 1, 0, 1]);    // blue
                matrix = matrix.concat([0, 0, 0, hide, 1]); // alpha

                filters = [ new ColorMatrixFilter(matrix) ];
            }
        }
     .......
        <s:HSlider id="_hide" right="8" bottom="30" width="80"
        minimum="0.25" maximum="1.00" value="1.00" stepSize="0.25"
        change="handleSlider(event)" />

gives me the error

Implicit coercion of a value with static type flash.events:Event 
    to a possibly unrelated type mx.events:SliderEvent.

How do I fix that? The Adobe HSlider doc is unusually sparse.

Is mx.events.SliderEvent still okay to use in a Flex 4.5 application?


The change event is not a SliderEvent; it dispatches a generic event. Just change the method signature for your event handler to remove the error.

    private function handleSlider(event:event):void { 

You can access the value of the slider just by accessing the slider directly:

var hide:Number = slider.value;

Or possibly using the target of the event:

var hide:Number = (event.target as HSlider).value;

The SliderEvent you refer to is an MX Event; and I do not believe it is used in the Spark implementation.

You may benefit from reviewing the ASDocs for the HSlider class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜