4 Replies Latest reply on Apr 11, 2009 3:19 PM by web.developer

    Using an XML request in CDATA & function name conflict

    web.developer

      Hi,

       

      I'm working on a script that downloads a file depending on the selection within a datagrid. How would I go about using {one.two.(@id == datagrd.selectedItem.uid).info.color} in a CDATA script? I need the download url to be dynamically changing. When I try to implement this method within CDATA though I get an error (1084: Syntax error: expecting colon before dot. --- 1084: Syntax error: expecting identifier before rightbrace).

       

      This is the code im using > private var FILE_URL:String =  {one.two.(@id == datagrd.selectedItem.uid).info.color};

       

      If I put quotes around it, it just sends that line as regular text. How would I go about making this work?

       

       

      Secondly, I have 2 functions I need to use and they are both called init() -- Full line of code > private function init():void

      If I keep them both at init() an error comes up (1021: Duplicate function definition) which makes sense because they are the same. The problem is if I change the name of one, the entire system its linked to (lets say to make a popup appear) doesn't work!

       

      I'm not really sure how to go about that one.

       

      Thanks for your help in advance,

      Jon

        • 1. Re: Using an XML request in CDATA & function name conflict
          Cyril Hanquez Adobe Community Professional

          Hi Jon,

           

          For your 1st problem, what about > private var FILE_URL:String =  "{one.two.(@id == "+datagrd.selectedItem.uid+").info.color}"; ?

           

          For your 2nd problem the only solution is to rename one of those function. What i don't understand is how you came up with 2 init() functions ? Is one of them public ? Can you give more details ?

           

          Cyril

          1 person found this helpful
          • 2. Re: Using an XML request in CDATA & function name conflict
            web.developer Level 1

            Hey Cyril,

             

            For the first problem, I changed the code to what you've stated and the entire app failed to launch. There were no errors in Flex when it was being compiled but when it launched in IE I got this error:

             

            TypeError: Error #1009: Cannot access a property or method of a null object reference.
                at myapp()[C:\Users\****\Documents\Flex Builder 3\myapp\src\myapp.mxml:53]
                at _myapp_mx_managers_SystemManager/create()
                at mx.managers::SystemManager/initializeTopLevelWindow()[E:\dev\3.0.x\frameworks\projects\fr amework\src\mx\managers\SystemManager.as:2438]
                at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::docFrameHandler()[E:\dev\3.0.x\frameworks\proj ects\framework\src\mx\managers\SystemManager.as:2330]

             

            Line 53 is the line with that code.

             

             

             

            For the second problem, I used code that I found on the Internet, one function's purpose is to launch a popup window, and the other function is to download a file. I skimmed both of the functions down to include only the necessary components. The code from the web came with the init() for both functions.

             

            They are both private functions.

             

            The error I get when I rename the popup function is >

             

            TypeError: Error #1009: Cannot access a property or method of a null object reference.
                at mx.managers::PopUpManagerImpl/addPopUp()[E:\dev\3.0.x\frameworks\projects\framework\src\m x\managers\PopUpManagerImpl.as:229]
                at mx.managers::PopUpManager$/addPopUp()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\m anagers\PopUpManager.as:169]
                at myapp/addNote()[C:\Users\****\Documents\Flex Builder 3\myapp\src\myapp.mxml:29]
                at myapp/___myapp_Button6_click()[C:\Users\****\Documents\Flex Builder 3\myapp\src\myapp.mxml:197]

             

            And the error I get when I rename the download function is >

             

            TypeError: Error #1009: Cannot access a property or method of a null object reference.
                at myapp/downloadSourceCodeZip()[C:\Users\****\Documents\Flex Builder 3\myapp\src\myapp.mxml:89]
                at myapp/__downloadBtn_click()[C:\Users\****\Documents\Flex Builder 3\myapp\src\myapp.mxml:186]

             

            Is there something I would need to add in order to rename the function?

            • 3. Re: Using an XML request in CDATA & function name conflict
              Cyril Hanquez Adobe Community Professional

              Oh I see what's wrong sorry... I assume that you are creating the string on the datagrid click event, so the correct code is :

               

              <mx:DataGrid id="datagrd" click="clickHandler(event)"/>

              <mx:Script>
                private var FILE_URL:String;
                public function clickHandler(event:MouseEvent):void   {       FILE_URL = "one.two.(@id == "+event.currentTarget.selectedItem.uid+").info.color";   } </mx:Script>

               

              I don't think that you need the curly brackets but if you need them it will be:

              FILE_URL = "{one.two.(@id == "+event.currentTarget.selectedItem.uid+").info.color}";

               

              For your second problem, I think that I need to see the code. Can you attach it ?

              1 person found this helpful
              • 4. Re: Using an XML request in CDATA & function name conflict
                web.developer Level 1

                I added the code you suggested and it didn't seem to work but after playing around with it for a bit I found the correct code:

                 

                [Bindable]
                private var FILE_URL:String;
                 
                  public function clickHandler(event:MouseEvent):void
                  {
                      FILE_URL = ""+allgames.game.(@id == event.currentTarget.selectedItem.gameid).url.dlurl+"";
                  }
                

                I had to add bindable to allow it to be attached properly to a label and the +'s you told me to add worked outside the code. I also tried not using the double quotes but it doesn't work for some reason without them :S

                Everything's working perfectly now, thank you for your help!

                 

                As to the second problem I figured it out, essentially init() was sort of a procedure that gets run right after the app loads. I think it may have something to do with this > creationComplete="init()" < that was located in the mx:application tag.

                I just combined all the lines of code from both init()'s into one function and it worked!

                 

                Thanks again for all your help!

                 

                Jon