0 Replies Latest reply on Mar 23, 2007 12:15 PM by lostchild

    how to add event listener in the class ?

    lostchild
      I want to seperate the code from the mxml completely . And here is my attempt but it is not working. I guess my problem is about adding the event listeners or setting the component id s in the class file. How should i change the code so that it works ? and any good practice advises are welcome. Thank you ...

      ////////////////////////////////// Code ///////////////////////////////////////////////////////

      ///////////////// MXML FILE //////////////////////////////////
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      applicationComplete="init()">
      <mx:Script>
      <![CDATA[
      import mx.controls.Alert
      import lostchild.DirectoryBrowser
      private var lcModel:DirectoryBrowser
      private function init():void{
      lcModel = new DirectoryBrowser()
      Alert.show("application complete", "Flex Debug")
      }
      ]]>
      </mx:Script>
      <mx:HDividedBox width="100%" height="100%">
      <mx:Button id="btn" width="100" height="100%"/>
      <mx:Text id="txt" height="100%" width="100%"/>
      </mx:HDividedBox>
      </mx:Application>


      //////// DirectoryBrowser.as placed in the folder "lostchild"//////////

      package lostchild{
      import flash.events.MouseEvent
      import mx.controls.Button
      import mx.controls.Text
      import mx.controls.Alert

      public class DirectoryBrowser{
      private var btn:Button = new Button()
      private var txt:Text = new Text()
      public function DirectoryBrowser():void{
      setStuff()
      Alert.show("class loaded","class debug")
      }
      public function callAlert(evt:MouseEvent):void{
      Alert.show("button clicked","debugging event handler")
      txt.text = "working fine"
      }
      public function setStuff():void{
      btn.label = "just click!"
      txt.text = " i can't get to see this !"
      btn.addEventListener(MouseEvent.CLICK,callAlert)
      }
      }
      }

      ( And why can't i see an attach code option in this message form ? )