actionscript 3 - FLEX - BitmapImage not updated after filters assigned -
i've flex mobile project , component (as-class) within of bitmapimage, button , graphic sign.
when boolean false button disabled, image gets grayness through colormatrixfilter (bitmapimage.filters = [mycmfilter]) , sign appers, else button enabled, image has no filters (bitmapimage.filters = []).
the problem image doesn't switch gray -> sign appears , button gets disabled.
if phone call setting of filters 1 frame later (calllater -> function setting filters) works.
i have extracted code sample project , works... without calllater
anyone thought can happpen in case???
christian
code:
package de.xxx.yyy.app.view.componentsv2.widgets { import de.assets.header.headerbgdarkgray; import de.assets.miscellaneous.stargrey; import de.assets.miscellaneous.staryellow; import de.assets.miscellaneous.underconstruction; import de.assets.imageassets; import de.xxx.yyy.app.view.componentsv2.buttons.basicbutton; import de.xxx.yyy.app.view.pools.userinterfacecomponentspool; import flash.debugger.enterdebugger; import flash.display.displayobject; import flash.display.sprite; import flash.events.event; import flash.events.mouseevent; import flash.filters.colormatrixfilter; import mx.core.ivisualelement; import mx.core.uicomponent; import spark.components.button; import spark.components.group; import spark.core.spritevisualelement; import spark.primitives.bitmapimage; public class stadiumwidget extends group{ private static var stadion_levels:int = 7; private static var side_spacing:int = 7; private static var button_width:int = 150; private static var button_height:int = 33; //////////////////////////////////////////////////////////////////////////// // user interface components //////////////////////////////////////////////////////////////////////////// private var underconstructionimage:underconstruction; private var currentimage:bitmapimage; private var footerbackground:headerbgdarkgray; private var developbutton:basicbutton; private var managebutton:basicbutton; private var displayedlevel:int; //////////////////////////////////////////////////////////////////////////// // fields //////////////////////////////////////////////////////////////////////////// private var createdstars:array = []; //////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////// private var _grayscalefilter:colormatrixfilter; public function grayscalefilter():colormatrixfilter { if(!_grayscalefilter) { var matrix:array = [0.3, 0.59, 0.11, 0, 0, 0.3, 0.59, 0.11, 0, 0, 0.3, 0.59, 0.11, 0, 0, 0, 0, 0, 1, 0]; _grayscalefilter = new colormatrixfilter(matrix); } homecoming _grayscalefilter; } public function set grayscalefilter(value:colormatrixfilter):void { _grayscalefilter = value; } //////////////////////////////////////////////////////////////////////////// // getter , setter dirty flag //////////////////////////////////////////////////////////////////////////// private var levelchanged:boolean; private var _level:int; public function set level(value:int):void { _level = value; levelchanged = true; invalidateproperties(); invalidatedisplaylist() } public function level():int { homecoming _level; } // private var isunderconstructionchanged:boolean; private var _isunderconstruction:boolean; public function set isunderconstruction(value:boolean):void { _isunderconstruction = value; isunderconstructionchanged = true; invalidateproperties(); invalidatedisplaylist() } public function isunderconstruction():boolean { homecoming _isunderconstruction; } //////////////////////////////////////////////////////////////////////////// // constructor //////////////////////////////////////////////////////////////////////////// public function stadium() { super(); } //////////////////////////////////////////////////////////////////////////// // lifecycle standard methods //////////////////////////////////////////////////////////////////////////// var testsprite:uicomponent; override protected function createchildren():void { super.createchildren(); currentimage = new bitmapimage(); currentimage.smooth = true; currentimage.percentwidth = 100; currentimage.scalemode = "letterbox"; addelement(currentimage); // footer footerbackground = new headerbgdarkgray(); addelement(footerbackground); developbutton = new basicbutton(); developbutton.width = button_width; developbutton.height = 38; developbutton.x = side_spacing; developbutton.label = resourcemanager.getstring("flexapp", "stadium.developbuttonlabel"); developbutton.addeventlistener(mouseevent.click, handledevelopbuttonclicked); addelement(developbutton); managebutton = new basicbutton(); managebutton.width = button_width; managebutton.height = 38; managebutton.label = resourcemanager.getstring("flexapp", "stadium.managebuttonlabel"); managebutton.addeventlistener(mouseevent.click, handlemanagebuttonclicked); addelement(managebutton); } override protected function commitproperties():void { super.commitproperties(); if(currentimage && levelchanged) { setcurrentimage(); setstars(); levelchanged = false; } if(isunderconstructionchanged) { setunderconstruction(); isunderconstructionchanged = false; } } override protected function measure():void { super.measure(); } override protected function updatedisplaylist(unscaledwidth:number, unscaledheight:number):void { super.updatedisplaylist(unscaledwidth, unscaledheight); var footer_height:int = footerbackground.getpreferredboundsheight(); var star_x_step:int = 25; footerbackground.y = unscaledheight - footer_height; footerbackground.width = unscaledwidth; managebutton.x = unscaledwidth - (button_width + side_spacing); managebutton.y = developbutton.y = footerbackground.y + ((footer_height - button_height) / 2); if(currentimage.height > unscaledheight - footerbackground.height) { currentimage.height = unscaledheight - footerbackground.height; } if(underconstructionimage) { underconstructionimage.x = (unscaledwidth - underconstructionimage.width) / 2; } var starstartx:int = unscaledwidth / 2 - (stadion_levels * star_x_step) / 2; var stary:int = createdstars.length > 0 ? unscaledheight - footer_height + (footer_height - createdstars[0].height) / 2 : 0; for(var i:int = 0; < createdstars.length; i++) { createdstars[i].y = stary; createdstars[i].x = starstartx + * star_x_step; } } //////////////////////////////////////////////////////////////////////////// // helper methods //////////////////////////////////////////////////////////////////////////// private function setstars():void { var pool:userinterfacecomponentspool = userinterfacecomponentspool.getinstance(); var star:ivisualelement; while(createdstars.length > 0) { star = createdstars.pop() ivisualelement; if(containselement(star)) { removeelement(star); } pool.disposeuserinterfacecomponent(star); } // pool stars!!! for(var i:int = 1; <= stadion_levels; i++) { if(i <= level) { star = pool.getyellowstar(); } else { star = pool.getgreystar(); } addelement(star) createdstars.push(star); } } private function setcurrentimage():void { if(level != displayedlevel) { currentimage.source = currentimages["level_" + level + "_name"]; displayedlevel = level; } setunderconstruction(); } private function setunderconstruction():void { developbutton.enabled = isunderconstruction == false; if(isunderconstruction) { if(!underconstructionimage) { underconstructionimage = new underconstruction(); underconstructionimage.y = 30; underconstructionimage.width = 330; underconstructionimage.height = 330; addelement(underconstructionimage); } calllater(setfilters, [true]); } else { calllater(setfilters, [false]); if(underconstructionimage && containselement(underconstructionimage)) { removeelement(underconstructionimage); } underconstructionimage = null; } } private function setfilters(value:boolean):void { if(value && (!currentimage.filters || currentimage.filters.length == 0)) { currentimage.filters = [grayscalefilter]; } else if(!value && currentimage.filters && currentimage.filters.length > 0) { currentimage.filters = []; } } //////////////////////////////////////////////////////////////////////////// // event handler //////////////////////////////////////////////////////////////////////////// private function handledevelopbuttonclicked(event:mouseevent):void { dispatchevent(new event("openlevelpopup", true)); } private function handlemanagebuttonclicked(event:mouseevent):void { dispatchevent(new event("openmanagepopup", true)); } //////////////////////////////////////////////////////////////////////////// // dispose //////////////////////////////////////////////////////////////////////////// public function dispose():void { developbutton.removeeventlistener(mouseevent.click, handledevelopbuttonclicked); managebutton.removeeventlistener(mouseevent.click, handlemanagebuttonclicked); } } }
actionscript-3 flex mobile air
No comments:
Post a Comment