3 Replies Latest reply on Mar 5, 2008 7:00 PM by ntsiii

    ViewStack

    SiHoop Level 1
      I'm trying to pass a variable to a ViewStack container. The following files work fine now, but I would to change it to pass the variable myVar2 to component1. So, the Label tag in component1 would be something like:
      <mx:Label text="{myVar2}"/>

      Of course, when I try this I get an error because myVar2 is undefined in the file component1.

      So, is it possible to pass a variable from one file to another?

      File1:Practice.mxml

      <?xml version="1.0"?>
      <mx:Application creationComplete="init()" xmlns:comp="components.*" xmlns:mx=" http://www.adobe.com/2006/mxml">
      <mx:Script>
      <![CDATA[
      [Bindable]
      private var myVar1:String
      [Bindable]
      private var myVar2:String
      private function init():void{
      myVar1="someContent"
      myVar2="someMoreContent"
      }
      ]]>
      </mx:Script><mx:Panel title="ViewStack">
      <mx:HBox>
      <mx:Button id="Panel1" label="Panel 1"
      click="myViewStack.selectedChild=linkPanel1;"/>
      <mx:Button id="Panel2" label="Panel 2"
      click="myViewStack.selectedChild=linkPanel2;"/>
      <mx:Button id="Panel3" label="Panel 3"
      click="myViewStack.selectedChild=linkPanel3;"/>
      </mx:HBox>
      <mx:ViewStack id="myViewStack">
      <mx:Canvas id="linkPanel1" label="Search" width="200" height="30">
      <mx:Label text="Initial text"/>
      </mx:Canvas>
      <comp:component1 id="linkPanel2" />
      <mx:Canvas id="linkPanel3" label="Search" width="200" height="30">
      <mx:Label text="{myVar1}"/>
      </mx:Canvas>
      </mx:ViewStack>
      </mx:Panel>
      </mx:Application>

      File 2: components/component1.mxml
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml">
      <mx:Canvas width="200" height="30">
      <mx:Label text="Panel 2 content"/>
      </mx:Canvas>
      </mx:Canvas>

      Thank you.