フレックス モバイル プロジェクトと、その中に BitmapImage、Button、および Graphic 記号を含むコンポーネント (as-Class) があります。
ブール値が false の場合、ボタンは無効になり、画像は ColorMatrixFilter (bitmapImage.filters = [myCMFilter]) によってグレーになり、記号が表示されます。そうでない場合、ボタンが有効になり、画像にフィルターがありません (bitmapImage.filters = [])。
問題は、画像が灰色に切り替わらない -> 記号が表示され、ボタンが無効になることです。
1 フレーム後にフィルターの設定を呼び出すと (callLater -> フィルターを設定する関数)、すべてが機能します。
コードをサンプル プロジェクトに抽出しましたが、すべてが機能します... callLater なしで
誰でも私の場合に何が起こるか考えていますか???
キリスト教徒
コード:
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 get 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);
}
return _grayscaleFilter;
}
public function set grayscaleFilter(value:ColorMatrixFilter):void
{
_grayscaleFilter = value;
}
////////////////////////////////////////////////////////////////////////////
// GETTER AND SETTER WITH 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 get level():int
{
return _level;
}
//
private var isUnderConstructionChanged:Boolean;
private var _isUnderConstruction:Boolean;
public function set isUnderConstruction(value:Boolean):void
{
_isUnderConstruction = value;
isUnderConstructionChanged = true;
invalidateProperties();
invalidateDisplayList()
}
public function get isUnderConstruction():Boolean
{
return _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; i < createdStars.length; i++)
{
createdStars[i].y = starY;
createdStars[i].x = starStartX + i * STAR_X_STEP;
}
}
////////////////////////////////////////////////////////////////////////////
// HELPER METHODS
////////////////////////////////////////////////////////////////////////////
private function setStars():void
{
var pool:UserInterfaceComponentsPool = UserInterfaceComponentsPool.getInstance();
var star:IVisualElement;
while(createdStars.length > 0)
{
star = createdStars.pop() as IVisualElement;
if(containsElement(star))
{
removeElement(star);
}
pool.disposeUserInterfaceComponent(star);
}
// POOL THE STARS!!!
for(var i:int = 1; i <= 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);
}
}
}