2012-06-05 73 views
0

我有一個新項目。和它的一部分,Flex是存在的。在「<mx:canvas>」中可以使用外部「<mx:script>」嗎?

<mx: Application xmlns:mx=...> 
    <mx:script> 
      import... 

      function A() { 
      } 
    </mx:script> 

    <mx:linkBar...> 
    <mxViewStack ...> 

     <mx:Canvas id="1st" ...> **[HERE]** </mx:Canvas> 
     <mx:canvas id="2nd" ...> ... </mx:Canvas> 
     <mx:canvas id="3rd" ...> ... </mx:Canvas> 

**當Viewstack按順序調用Canvas時,A()必須工作。

是否可以在**HERE**]中使用函數A()?

或請讓我知道可以使用的功能或標籤。

+0

這是可能的,但你是什麼意思通過「使用」?你想要這個功能做什麼,什麼時候做? – izhak

+0

呵呵?什麼??請澄清 –

回答

1

進行調度下面的例子可以幫助你的附加屬性: -

<?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"> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 
    <fx:Script> 
     <![CDATA[ 

      private function A():void 
      { 
       //Your code 
      } 

      private function viewStackHandler():void 
      { 
       //Method One 
       if(viewStackID.selectedIndex == 0) 
       { 
        A(); 
       } 
       else if(viewStackID.selectedIndex == 1) 
       { 
        A(); 
       } 
       else 
       { 
        A(); 
       } 
       //OR Method Second 
       //call only A() 


      } 

     ]]> 
    </fx:Script> 
    <mx:VBox width="100%" height="100%"> 
     <mx:HBox width="100%" height="20"> 
      <s:Button label="One" click="{viewStackID.selectedIndex = 0}"/> 
      <s:Button label="Two" click="{viewStackID.selectedIndex = 1}"/> 
      <s:Button label="Three" click="{viewStackID.selectedIndex = 2}"/> 
     </mx:HBox> 
     <mx:ViewStack width="500" height="400" id="viewStackID" change="viewStackHandler()"> 
      <mx:Canvas id="canval1" borderColor="#FF0000" width="100%" height="100%"> 
       <s:Button label="One"/> 
      </mx:Canvas> 
      <mx:Canvas id="canval2" borderColor="#00FF00" width="100%" height="100%"> 
       <s:Button label="Two"/> 
      </mx:Canvas> 
      <mx:Canvas id="canval3" borderColor="#0000FF" width="100%" height="100%"> 
       <s:Button label="Three"/> 
      </mx:Canvas> 
     </mx:ViewStack> 
    </mx:VBox> 
</s:Application> 
0

可以使用當畫布添加到則ViewStack

<mx:Canvas id="1st" add="A()"></mx:Canvas> 
相關問題