![]() |
|
||||||||||
|
|||||||
|
|
« Предыдущая тема | Следующая тема » |
| Опции темы | Опции просмотра |
|
![]() |
![]() |
|
|||||
|
Здравствуйте
я сделал кастомный Hslider с 2мя кнопками "+" и "-" для увеличения уменьшения value Но в компоненте value при нажатии на эти кнопки почему-то NaN Причем, это всегда до того момента как я мышкой первый раз двину thumb слайдера, после этого компонент знает свою value Почему так и что доделать ? вот компонент package com { import flash.events.Event; import flash.events.MouseEvent; import spark.components.Button; import spark.components.HSlider; public class CustomHSlider extends HSlider { public function CustomHSlider() { super(); } [SkinPart(required="true")] public var decreaseValueButton:Button; [SkinPart(required="true")] public var increaseValueButton:Button; override public function set value(newValue:Number):void { super.value=newValue; } override protected function partAdded(partName:String, instance:Object):void { super.partAdded(partName, instance); if(instance == decreaseValueButton) { decreaseValueButton.addEventListener(MouseEvent.CLICK,decreaseValueButtonClickHandler); } if(instance == increaseValueButton) { increaseValueButton.addEventListener(MouseEvent.CLICK,increaseValueButtonClickHandler); } } override protected function partRemoved(partName:String, instance:Object):void { super.partRemoved(partName, instance); if(instance == decreaseValueButton) { decreaseValueButton.buttonMode=true; decreaseValueButton.addEventListener(MouseEvent.CLICK,decreaseValueButtonClickHandler); } if(instance == increaseValueButton) { increaseValueButton.buttonMode=true; increaseValueButton.addEventListener(MouseEvent.CLICK,increaseValueButtonClickHandler); } } protected function decreaseValueButtonClickHandler(event:MouseEvent):void { commitProperties(); value-=snapInterval; dispatchEvent(new Event(Event.CHANGE)); } protected function increaseValueButtonClickHandler(event:MouseEvent):void { commitProperties(); value+=snapInterval; dispatchEvent(new Event(Event.CHANGE)); } } } <?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:fb="http://ns.adobe.com/flashbuilder/2009" xmlns:assets="assets.*" minHeight="11" alpha.disabled="0.5"> <fx:Metadata> <![CDATA[ [HostComponent("com.CustomHSlider")] ]]> </fx:Metadata> <fx:Script> override protected function measure() : void { var thumbPos:Number = thumb.getLayoutBoundsX(); thumb.setLayoutBoundsPosition(0, thumb.getLayoutBoundsY()); super.measure(); thumb.setLayoutBoundsPosition(thumbPos, thumb.getLayoutBoundsY()); } </fx:Script> <s:states> <s:State name="normal" /> <s:State name="disabled" /> </s:states> <fx:Declarations> </fx:Declarations> <assets:HSliderBackground left="-6" right="-6" top="-3"/> <s:Button id="track" left="0" right="0" top="2" minWidth="33" width="100" tabEnabled="false" skinClass="com.skins.HSliderTrackSkin" buttonMode="true"/> <s:Button id="thumb" width="11" height="11" tabEnabled="false" skinClass="com.skins.HSliderThumbSkin" buttonMode="true"/> <s:Button id="decreaseValueButton" skinClass="com.skins.HSliderDecreaseButtonSkin" left="-20" buttonMode="true" tabEnabled="false"/> <s:Button id="increaseValueButton" skinClass="com.skins.HSliderIncreaseButtonSkin" right="-20" buttonMode="true" tabEnabled="false"/> </s:SparkSkin> |
|
|||||
|
У HSlider (точнее у его предка TrackBase) есть метод changeValueByStep используйте его для увеличения и уменьшения значения. В нем же будет отправлено CHANGE.
Зачем вы вызываете commitProperties() напрямую? Тем более, что сами его никак не используете. Изменение value вызовет invalidateProperties, что в свою очередь вызовет commitProperties. Вы всю логику компонента перекорежили.
__________________
משיח לא בא משיח גם לא מטלפן |
|
|||||
|
Это я забыл убрать, прошу прощения.
Спасибо за ответ Чем, коммитами или насильным диспатчем события ? Все равно, value изначально NaN Я вот как переделал protected function decreaseValueButtonClickHandler(event:MouseEvent):void { if(isNaN(value)) { value=1.1; } else { this.changeValueByStep(false); } } protected function increaseValueButtonClickHandler(event:MouseEvent):void { if(isNaN(value)) { value=1.1; } else { this.changeValueByStep(true); } } Последний раз редактировалось djyamato; 26.03.2012 в 20:01. |
|
|||||
<com:CustomHSlider minimum="{AppData.getInstance().minZoom}" maximum="{AppData.getInstance().maxZoom}" value="{AppData.getInstance().currentZoom}" snapInterval=".1" stepSize=".1" liveDragging="true" mouseFocusEnabled="false" mouseWheel="hslider1_mouseWheelHandler(event)" change="hslider1_changeHandler(event)"/> |
|
|||||
|
Цитата:
__________________
משיח לא בא משיח גם לא מטלפן |
![]() |
![]() |
Часовой пояс GMT +4, время: 19:43. |
|
|
« Предыдущая тема | Следующая тема » |
| Опции темы | |
| Опции просмотра | |
|
|