4 Replies Latest reply on Jan 5, 2010 10:11 PM by LaVengeance

    problem in  code

    naval joshi

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="creationCompleteHandler(event);">

       

      <mx:Script>

      <![CDATA[

      import flash.events.*;

      import mx.events.FlexEvent;

      [Bindable]

       

                  private function creationCompleteHandler(event:FlexEvent):void

                  {

                      // Listen for the click event on the Button control

                      myButton.addEventListener (MouseEvent.CLICK, handler);

                  }

      public function handler(e:MouseEvent):void

      {

      var j:URLLoader=new URLLoader();

      var req:URLRequest=new URLRequest("C:\Users\nikhiljoshi122\Desktop\naval files\flex\xmln\nj.xml");

      j.load(req);

      j.addEventListener(Event.COMPLETE,loaded);

      }

      private function loaded(e:Event):void

      {

      var temp_xml:XML=e.currentTarget.Data;

      trace(temp_xml)

      myButton.label ="loaded";

      }

       

      ]]>

      </mx:Script>

      <mx:TextArea x="157" y="68" width="175" height="150" id="t1" text="{temp_xml}"/>

       

      <mx:Label x="157" y="42" text="data file" width="113"/>

          <mx:Button id="myButton" label="Click Me!"  x="167" y="226"/>

      </mx:Application>

       

       

       

       

      /////////

      I am a new learner of flex action script.............heres ma code.i m nt getting the xml loaded in the datagrid.....flex builder says at line 10 in creationcomplete handler function it requiresan event name parameter  with [bindable]......

      i m nt gettin...pls help

        • 1. Re: problem in  code
          rgadiparthi Level 2

          seems your xml is not formated properly.

           

          try to find the problem and correct it or else attach your xml here.

           

          Thanks

          • 2. Re: problem in  code
            LaVengeance Level 1

            Some issues:

             

                 -  I don't see a datagrid here, but a TextArea

                 - You can't assign a variable of type XML to a text area, it needs to be of type String

                 - the variable temp_xml needs to be declared at the class level so that it is visible to components outside of the private function in which you are             updating it

                 - It's better to avoid spaces in the URLs that you use, I'm not so sure if it will fail but it's good to avoid spaces in URLs ( change your folder name from  naval files to something like naval_files)

             

            the code below should work fine :



            <?xml version="1.0" encoding="utf-8"?>

             

            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="creationCompleteHandler()">

             

             

             

            <mx:Script>

             

            <![CDATA[

             

            import flash.events.*;

             

            import mx.events.FlexEvent;

             

            [Bindable]

             

            var temp_xml:String;

             

            private function creationCompleteHandler():void

             

                        {

             

                            // Listen for the click event on the Button control

             

                            myButton.addEventListener (MouseEvent.CLICK, handler);

             

                        }

             

            public function handler(e:MouseEvent):void

             

            {

             

            var j:URLLoader=new URLLoader();

             

            var req:URLRequest=new URLRequest("C:\Users\nikhiljoshi122\Desktop\naval_files\flex\xmln\nj.xml");

             

            j.load(req);

             

            j.addEventListener(Event.COMPLETE,loaded);

             

            }

             

            private function loaded(e:Event):void

             

            {

             

            temp_xml=e.currentTarget.data as String;

             

            trace(temp_xml)

             

            myButton.label ="loaded";

             

            }

             

             

             

            ]]>

             

            </mx:Script>

             

            <mx:TextArea x="157" y="68" width="175" height="150" id="t1" text="{temp_xml}"/>

             

             

             

            <mx:Label x="157" y="42" text="data file" width="113"/>

             

                <mx:Button id="myButton" label="Click Me!"  x="167" y="226" />

             

            </mx:Application>

             


             

            Cheers

            1 person found this helpful
            • 3. Re: problem in  code
              naval joshi Level 1

              thanxx ....problem solved!!

              • 4. Re: problem in  code
                LaVengeance Level 1

                glad to be of help !

                 

                Good luck