是否可以在“<mx:canvas>”中使用“<mx:script>”外部?</mx:canvas> </mx:script>

时间:2012-06-05 02:24:05

标签: flex

我有一个新项目。还有一部分,Flex存在。

<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()?

或者,请告诉我可能使用的功能或标签。

2 个答案:

答案 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>

答案 1 :(得分:0)

您可以使用将Canvas添加到ViewStack

时调度的add属性
<mx:Canvas id="1st" add="A()"></mx:Canvas>