3 Replies Latest reply on Sep 29, 2006 2:44 AM by yoyesman

    Changing container State from a component

    Level 1
      Hi, I try to change the state of an application from a button inside a mxml component. I found a way for this by handling click event inside the component and dispatch event to the container (see the code below). But my problem is that any click is dispatched ! I would like that only one button dispatch this event, or better : calling a container's function from the button inside my component ! Is this possible ?

      Thanks for your help

      Here is a part of the container code :

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="570" height="360" xmlns:local="*">
      <mx:Script>
      <![CDATA[
      import flash.events.Event;
      public function handleCloseEvent(eventObj:Event):void {
      currentState='carte';
      }
      ]]>
      </mx:Script>

      <mx:states>
      <mx:State name="liste">
      <mx:AddChild position="lastChild">
      <local:liste_vin_region click="handleCloseEvent(event);" id="fenetre">
      </mx:AddChild>
      </mx:State>
      <mx:State name="carte"/>
      </mx:states>
      </mx:Canvas>

      And the component code :

      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="514" height="300" xmlns:local="*">
      <mx:Metadata>
      [Event(name="click", type="flash.events.Event")]
      </mx:Metadata>

      <mx:Script>
      <![CDATA[
      import flash.events.Event;
      // Redispatch event.
      private function handleCloseEventInternally(eventObj:Event):void {
      dispatchEvent(eventObj);
      }
      ]]>
      </mx:Script>

      <mx:states>
      <mx:State name="liste"/>
      </mx:states>
      <mx:TitleWindow layout="absolute" left="10" top="10" bottom="10" right="10" id="titlewindow1"/>
      <mx:Button y="14" label="X" right="19" width="29" click="handleCloseEventInternally(event);" id="button1"/>
      </mx:Canvas>