Quite wierd bug i am experiencing with Flex 4.6, with a very simple piece of code.
for ( var j=0 ; j< chip_num; j++)
{
isoChip = new IsoChip();
//isoChip.type=(IsoChip.YELLOW_CHIP); //<<<<<<<<<DOESNOT WORK HERE
isoChip.scaleX = isoChip.scaleY=1//0.45 ;
isoChip.x= i + 10 * i + 5 ;
isoChip.y= y_num;
addElement(isoChip);
isoChip.type=(IsoChip.YELLOW_CHIP); //<<<<<<<<<<<<<<WORKS HERE ONLY
y_num = y_num - 2.5 //IsoChip.height ;
}
Having this component : IsoChip.mxml component
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="23" height="20" initialize="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
public static const BLUE_CHIP:String = "blueChip" ;
public static const BLACK_CHIP:String = "blackChip" ;
public static const YELLOW_CHIP:String = "yellowChip" ;
public function init(type_val_str="blueChip")
{
blueChip.visible= false;
blackChip.visible =false ;
yellowChip.visible = false ;
//type = type_val_str ;
}
function set type(type_val_str:String)
{
switch( type_val_str)
{
case IsoChip.BLUE_CHIP:
trace(">",IsoChip.BLUE_CHIP)
blueChip.visible = true;
blackChip.visible = false ;
yellowChip.visible = false ;
break;
case IsoChip.BLACK_CHIP:
trace(">",IsoChip.BLACK_CHIP)
blueChip.visible = false ;
blackChip.visible = true ;
yellowChip.visible = false ;
break;
case IsoChip.YELLOW_CHIP:
trace(">",IsoChip.YELLOW_CHIP)
blueChip.visible = false;
blackChip.visible = false ;
yellowChip.visible = true;
break;
}
}
]]>
</fx:Script>
<s:SWFLoader id="blueChip" x="0" y="0" width="23" height="20" source="../swf/blue-iso-chip.swf"/>
<s:SWFLoader id="yellowChip" x="-16" y="5" width="23" height="20" source="../swf/yellow-iso-chip.swf"/>
<s:SWFLoader id="blackChip" x="4" y="9" width="23" height="20" source="../swf/black-iso-chip.swf"/>
</s:Group>
Is it really a bug. Or am i doing something wrong ??
I suggest using states here instead of visibility.
So, declare 3 states in your group:
Then apply each state for each SWFLoader:
And at last, in the ActionScript code change the state based on the condition: