![]() |
|
||||||||||
|
|||||
|
Здравствуйте
Я в замешательстве Сделал кнопку из ms:Image такой чтобы она получала стэйты и пути к картинкам стэйтов. Каждый из стэйтов для своего удобства я собрал в ValueObject (его код) со свойствами stateName-имя стэйта ("normal", "over" итд), stateURL - путь к картике для стэйта и stateData - сюдазаносится закэшированный Bitmap При первой установки определенного стэйта, после загрузки картинки, кнопка кэширует эту картинку (Bitmap) и в дальнейшем при возвращении к этому стэйту отображает кэш (Bitmap). Первые 2 раза (подгрузка картинки стэйта и отображение закэшированного стэйта срабытывают, а 3й раз при установки этого же стэйта Bitmap в кэше почему-то имеет значения ширины и высоты равными нулю) Что не так ? Вот пример работы View source Повторюсь: устанавливается стэйт "normal" - загружается картинка, отправляется в кэш, затем стэйт "over" -загружается картинка, отправляется в кэш, затем опять "normal" - картинка корректная берется из кэша, затем опять "over" - картинка в кэше почему-то нулевых размеров, опять "normal" - картинка в кэше нулевых размеров вот код: <fx:Script> <![CDATA[ import com.CacheableImageStateVO; import com.CacheableImageStatesDataVO; import mx.events.FlexEvent; protected function CacheableButton_rollOverHandler(event:MouseEvent):void { cacheableButton.state="over"; } protected function CacheableButton_rollOutHandler(event:MouseEvent):void { cacheableButton.state="normal"; } protected function application1_creationCompleteHandler(event:FlexEvent):void { var rightButtonStateData:CacheableImageStatesDataVO=new CacheableImageStatesDataVO(); var rightButtonEnabledState:CacheableImageStateVO=new CacheableImageStateVO(); rightButtonEnabledState.stateName="normal"; rightButtonEnabledState.stateImageURL="assets/controls/RightArrowControlEnabled.png"; rightButtonStateData.addState(rightButtonEnabledState); var rightButtonDisabledState:CacheableImageStateVO=new CacheableImageStateVO(); rightButtonDisabledState.stateName="disabled"; rightButtonDisabledState.stateImageURL="assets/controls/RightArrowControlDisabled.png"; rightButtonStateData.addState(rightButtonDisabledState); var rightButtonOverState:CacheableImageStateVO=new CacheableImageStateVO(); rightButtonOverState.stateName="over"; rightButtonOverState.stateImageURL="assets/controls/RightArrowControlOver.png"; rightButtonStateData.addState(rightButtonOverState); cacheableButton.statesData=rightButtonStateData; cacheableButton.state="normal"; } ]]> </fx:Script> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <com:CacheableImage id="cacheableButton" rollOver="CacheableButton_rollOverHandler(event)" rollOut="CacheableButton_rollOutHandler(event)"/> <?xml version="1.0" encoding="utf-8"?> <mx:Image xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" currentState="normal" complete="image1_completeHandler(event)" ioError="image1_ioErrorHandler(event)"> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <mx:states> <s:State name="normal"/> <s:State name="over"/> <s:State name="disabled"/> <s:State name="playing"/> <s:State name="stopped"/> </mx:states> <fx:Script> <![CDATA[ import mx.utils.ObjectUtil; protected var _statesData:CacheableImageStatesDataVO; protected var _bounds:Object; override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { if(_bounds) { graphics.clear(); graphics.beginFill(0xFF0000,1); graphics.drawRect(0,0,_bounds.width,_bounds.height); graphics.endFill(); } super.updateDisplayList(unscaledWidth, unscaledHeight); } public function set statesData(val:CacheableImageStatesDataVO):void { _statesData=val; } public function set state(val:String):void { currentState=val; if(_statesData) { var stateData:Object=_statesData.getStateDataByName(val); if(stateData) { trace("using cache "+stateData+" w="+stateData.width+" h="+stateData.height); source=stateData; } else { trace("using URL "+_statesData.getStateURLByName(val)); source=_statesData.getStateURLByName(val).toString(); } } else { throw new Error("CacheableImage Error: statesData must be set before set states"); } } protected function image1_completeHandler(event:Event):void { trace("SOURCE load complete "+content+" w="+content.width+" h="+content.height); if(!_bounds) { _bounds=new Object(); _bounds.width=content.width; _bounds.height=content.height; } trace("Trying to get cache "+_statesData.getStateDataByName(currentState)) if(!_statesData.getStateDataByName(currentState)) { trace("setting this "+content+" as cache for state "+currentState); _statesData.setStateDataByName(currentState,new Bitmap((content as Bitmap).bitmapData)); } } protected function image1_ioErrorHandler(event:IOErrorEvent):void { trace("SOURCE load ioError: "+event.text); } ]]> </fx:Script> </mx:Image> |
![]() |
![]() |
Часовой пояс GMT +4, время: 07:25. |
|
|
« Предыдущая тема | Следующая тема » |
|
|