2012-05-07 67 views
-1

我的問題是這樣的:
我想使用mxml作爲可視元素...我想以圖形方式設置組件,並將其作爲類編程,因爲它對我來說很簡單...如何做到這一點???我有兩個類:一個是和一個MXML ...這是我的代碼:ActionScript 3和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

是這個okey代碼?因爲當我運行它只是播放空白頁... – Jovan

+0

對我來說,它顯示了三個定義的按鈕,沒有別的。它展示的是什麼? –

回答

0

首先,你的AS3代碼是liiiittle有點古怪。

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文件。

+0

現在我有一個錯誤:無法找到組件類'fm.domain.H264'的指定基類'VideoChat'。任何想法??? – Jovan

+0

當我喜歡你建議在這裏,在mxml文件,在大綱我沒有容器...只是在紅色!根....也許這是問題... – Jovan

+0

@Jovan你的第一個錯誤是相關的編碼,我沒有看到,所以我不能說。另外,我不明白你對容器的意思。 –