Wednesday, April 13, 2011

Flex Application and Component



//compapp.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:comp="*"  layout="absolute">
      <mx:Script>
            <![CDATA[
                  import mx.core.Application;
                  import mx.core.Container;
                  import mx.controls.Alert;

                  public var a:int=100;
                 
                  private function changeit():void
                  {
                        comp1.b=10;
                        if(comp1.comp2 !=null)
                        {
                        comp1.comp2.c=21;
                        }
                  }
            ]]>
      </mx:Script>
      <mx:ViewStack id="view" height="100%" width="100%">
            <mx:VBox id="first">
             <mx:Button id="clicktoswitch" label="Go To Component1" click="view.selectedChild=comp1"/>
             <mx:Button id="change" label="change" click="changeit()"/>

            </mx:VBox>
                  <comp:component1 id="comp1"/>
                 
      </mx:ViewStack>
</mx:WindowedApplication>

//outercomponent.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" show="hi()" xmlns:comp="*" width="400" height="300">
     
      <mx:Script>
            <![CDATA[
            import mx.core.Application;
            import mx.controls.Alert;
            import mx.core.Container;
            public var b:int=0;
            private function changeit():void
                  {
                        Application.application.a=1000;
                        comp2.c=50;
                       
                       
                  }

                  public function DoThis():void
                  {
                 
                        Application.application.view.selectedChild=Application.application.first;
                  }
                  public function hi():void
                  {
                        trace("in hi");
                        view1.selectedChild=first;
                        //view1.selectedChild=comp2;
                  }
            ]]>
      </mx:Script>
      <mx:ViewStack id="view1" width="100%" height="100%">
            <mx:VBox id="first" horizontalAlign="center" verticalAlign="middle">
                  <mx:Button id="clicktoswitch" label="Go To Component2" click="view1.selectedChild=comp2"/>
                  <mx:Button id="BacktoMain" label="Back To Main" click="DoThis()" width="133" height="23"/>
                                    <mx:Button id="change" label="change" click="changeit()"/>

            </mx:VBox>
            <comp:innercomponent id="comp2"/>
      </mx:ViewStack>
</mx:Canvas>

//innercomponent.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
<mx:Script>
      <![CDATA[
      import mx.controls.Alert;
      import mx.core.Application;
      public var c:int=10;

            private function changeit():void
                  {
                      Application.application.a=10000;
                        Application.application.comp1.b=20000;
                  }
      ]]>
</mx:Script>
      <mx:Button id="back" label="Back To Main" click="Application.application.view.selectedChild=Application.application.first"/>
      <mx:Button id="back1" label="change comp1's view" click="Application.application.comp1.view1.selectedChild=Application.application.comp1.first" x="55" y="96"/>
                  <mx:Button id="change" label="change" click="changeit()" x="134" y="181"/>

</mx:Canvas>



No comments:

Post a Comment