Archive for 07月, 2008

  • Adobe说:

    “You can use the [Embed] metadata tag to import
    JPEG, GIF, PNG, SVG, SWF, TTF, and MP3 files.”
    

    但我们可以通过下面的方法将XML也作为资源嵌入进SWF中

    package example
    {
    import mx.core.ByteArrayAsset;
    
    public final class Config
    {
    [Embed("config.xml", mimeType="application/octet-stream")]
    private static const Config:Class;
    
    public static function getConfig() : XML
    {
    var ba:ByteArrayAsset = ByteArrayAsset( new Config()) ;
    var xml:XML = new XML( ba.readUTFBytes( ba.length ) );
    
    return xml;
    }
    }
    }

    作者已经把此方法封装成了XMLAsset类,原文见这里

    http://www.ericfeminella.com/blog/2008/07/27/xmlasset-api/

  • 普通模式下切换为全屏模式,全屏模式下切换为普通模式。

    代码:

    _btn.addEventListener(MouseEvent.CLICK,fullScreen);
    function fullScreen(e:MouseEvent):void {
    stage.displayState = stage.displayState == StageDisplayState.NORMAL ? StageDisplayState.FULL_SCREEN : StageDisplayState.NORMAL;;
    }
    
  • 附件中有源文件与示例,只是在此对附件做些说明。
    com.rictus.reflector.Reflector.as是这个组件的核心文件,在我们的工程中,只需要导入这一个文件。
    com.rictus.dragpanel.DragPanel.as是另外一个组件,和倒影完全没有关系。这是一个可以拖动的Panel组件。
    LiveReflection.mxml是示例文件。

    使用时参照LiveReflection.mxml中的用法即可,需要注意的是被设置倒影的对象必须要有height高度属性。

    livereflection.zip

  • 从Container的Child层次来讲,Container可分为两类。第一类是像VBox等,容器中所有Child都将被同时显示的。第二类是像ViewStack等,Child会分别显示。

    默认情况下,第一类容器的所有Child,是在容器被实例化时全部实例化,而第二类容器的Child,将会在首次访问的时候,才被实例化。

    creationPolicy属性,就是改变这种默认情况的。其取值有4个:”auto”, “all”, “none”, “queued”。

    默认值是auto,当我们使用ViewStack这种容器时,将creationPolicy=all,即可立即实例化所有Child。

  • Adobe是这样说的:

    Specifies whether this component is included in the layout of the parent container.
    If true, the object is included in its parent container’s layout.
    If false, the object is positioned by its parent container as per its layout rules, but it is ignored for the purpose of computing the position of the next child.

    The default value is true.

    This property can be used as the source for data binding.

    很多时候,这个属性可以实现的功能,有些类似于CSS中的display:block/none

    但是,在Flex中,将includeInLayout设置为false,并不代表从“布局”中“隐藏”掉这个UIComponent,而仅仅是将这个UIComponent从布局中忽略,直接布局下一个对象。

    如果想完全从容器中隐藏掉一个对象,请同时使用visible=”false” includeInLayout=”false”

    请参阅下面三个设置了includeInLayout的Panel的例子

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
    	<mx:Panel>
    		<mx:TextInput/>
    		<mx:TextInput includeInLayout="false"/>
    		<mx:TextInput/>
    	</mx:Panel>
    	<mx:Panel>
    		<mx:TextInput/>
    		<mx:TextInput visible="false" includeInLayout="false"/>
    		<mx:TextInput/>
    	</mx:Panel>
    	<mx:Panel>
    		<mx:TextInput/>
    		<mx:TextInput includeInLayout="false"/>
    	</mx:Panel>
    </mx:Application>

    运行效果:

  • 在要编译的工程上点右键 -> Properties -> Flex Compiler
    在Additonal compiler arguments中输入

    -keep-generated-actionscript=true
    

    编译此Flex工程后,Flex Builder将在src文件夹(源文件的文件夹)下面创建一个名为generated的文件夹,里面为此工程的纯AS文件。