【发布时间】:2011-04-01 12:12:56
【问题描述】:
我在 flex 中有这个源 - 在两种状态之间切换的简单程序..在第二种状态是显示 myImage 组件
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:components="components.*">
<fx:Script>
<![CDATA[
protected function button1_clickHandler(event:MouseEvent):void
{
if (currentState == "state1")
currentState = "state2";
else
currentState = "state1";
}
]]>
</fx:Script>
<s:states>
<s:State name="state1" />
<s:State name="state2" />
</s:states>
<components:myImage includeIn="state2"/>
<s:Button label="switch states" click="button1_clickHandler(event)" />
</s:Application>
组件 myImage 在这里:
<?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" >
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function img_creationCompleteHandler(event:FlexEvent):void
{
trace("image width " + img.width);
}
]]>
</fx:Script>
<mx:Image id="img" source="obr.jpg" creationComplete="img_creationCompleteHandler(event)"/>
</s:Group>
如果将与 myImage.mxml 相同的代码放入主应用程序,则跟踪打印正确的值..但是现在当我单击按钮并切换到 state2 时,跟踪打印宽度为 0..为什么?在哪个事件之后加载 state2 中的图像,我可以使用 image.width 属性??
感谢帮助
【问题讨论】:
标签: apache-flex actionscript-3 mxml flash-builder