ActionScript 3和mxml

时间:2012-05-07 15:09:15

标签: actionscript-3 flash flex flash-builder mxml

我的问题是:
我想使用mxml作为视觉元素...我想以图形方式设置组件并在一个类中编程,因为它对我来说很容易......怎么做?我有两个类:一个和一个mxml ......这是我的代码:

public class chat extends Application{
    private var nc:NetConnection = null;
    public var connect:Button;      
    public var status:Text;

    public function VideoChat(){
        addEventListener(FlexEvent.APPLICATION_COMPLETE, mainInit);
    }

    private function mainInit(event:FlexEvent):void{            
        status.text = "Status quo";

        connect.addEventListener(MouseEvent.CLICK, doConnect);
    }

和mxml:

<?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"
           minWidth="955" minHeight="600" backgroundColor="#FBF8F8"
           preloaderChromeColor="#CC3535" 
           >

    <mx:Button x="77" y="547" height="19" label="Connect" id="connect"/>
    <mx:UIComponent id="videoReceiveContainer" x="77" y="52" width="500" height="400"/>
    <mx:Button x="507" y="547" label="Play" id="play"/>
    <mx:Text id="status" x="77" y="460" width="501" height="58"/>
    <mx:Button x="297" y="547" label="Publish" id="publish"/>
</s:Application>

1 个答案:

答案 0 :(得分:0)

首先,你的AS3代码很简单。

public class VideoChat extends Application{
    private var nc:NetConnection = null;
    public var connect:Button;      
    public var status:Text;

    public function VideoChat(){
        addEventListener(FlexEvent.APPLICATION_COMPLETE, mainInit);
    }

    private function mainInit(event:FlexEvent):void{            
        status.text = "Status quo";

        connect.addEventListener(MouseEvent.CLICK, doConnect);
    }
}

类的名称必须与构造函数的名称匹配。

其次,MXML:

<?xml version="1.0" encoding="utf-8"?>
<local:VideoChat 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:local="*"
                 minWidth="955" minHeight="600" backgroundColor="#FBF8F8"
                 preloaderChromeColor="#CC3535" 
                 >

    <mx:Button x="77" y="547" height="19" label="Connect" id="connect"/>
    <mx:UIComponent id="videoReceiveContainer" x="77" y="52" width="500" height="400"/>
    <mx:Button x="507" y="547" label="Play" id="play"/>
    <mx:Text id="status" x="77" y="460" width="501" height="58"/>
    <mx:Button x="297" y="547" label="Publish" id="publish"/>
</local:VideoChat>

如果您注意到,我将XML命名空间定义为“本地”xmlns:local="*"s:Application标记已替换为local:VideoChat

最后,您在评论中询问了加载页面的路径。它应该是...bin-debug/name.html。此HTML文件是一个包装器,显示项目的已编译SWF。