6 Replies Latest reply on Sep 3, 2010 11:23 AM by Jerry62712

    How do I execute a script/function?

    Jerry62712 Level 1

      I have a component called Search.mxml.  I have a script/as file called AccessibleFormS.as.  That file has one function in it called sAccessibility().

       

      Search.mxml

      ...

      <mx:Script source="../ASFiles/AccessibleFormS.as"/>
      ...

       

      AccessibleFormS.as

      ...

      public function sAccessibility():void {
          if (sSODC.accessibilityProperties.name == "SODC")
              return;        // already been here

       

          // establish buttons and header *******************************************
          sHeader.accessibilityProperties = new AccessibilityProperties();
          sHeader.accessibilityProperties.name = "Search Form";
          sHeader.accessibilityProperties.
              description = "Search Form";
      ...

       

      The question is how do I execute that function from within the component?

       

      TIA,

      Jerry

        • 1. Re: How do I execute a script/function?
          Gregory Lafrance Level 6

          I think you can just execute the function, simple as that.

           

          Of course, the question becomes when should you execute it. If you want it executed at app startup, the use the creationComplete event handler.

           

          Or maybe it will be a button click handler.

           

          Because you'll want to do that in a <script> block, you're probably better off "including" the as file:

           

          include "mydir1/mydir2/myASFile.as";

           

          If this post answers your question or helps, please mark it as such.


          Greg Lafrance - Flex 2 and 3 ACE certified

          www.ChikaraDev.com

          Flex Training and Support Services

          • 2. Re: How do I execute a script/function?
            krafttimd Level 2

            here's an example:

             

                <mx:Script source="testScript.as"><![CDATA[
                        doSomething()
            ]]></mx:Script>

            • 3. Re: How do I execute a script/function?
              Jerry62712 Level 1

              Thanks for both your replies.

               

              I tried adding the execution to the script that defines it and get this error.  Here is the warning:

              Ignoring inline script because a source was specified.

               

              Here is the exact code:

              <mx:Script source="../ASFiles/AccessibleFormS.as">
              <![CDATA[sAccessibility()]]>
              </mx:Script>

              located in the component.

               

              I also tried adding the function name to the existing script in the component:

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
                  width="100%">

              // below is line 5

              <mx:Script source="../ASFiles/AccessibleFormS.as"/>

               

              <mx:Script>
                  <![CDATA[
                  import mx.events.ListEvent;

               

                   sAccessibility();          // line 11

               

                  [Bindable] public var SODCName:Array;
                  [Bindable] public var dmSearch:XML;


              Line five defines the script file and line eleven executes the one function in that file.  This is the error associated with line 11:

              1180: Call to a possibly undefined method sAccessibility.

              • 4. Re: How do I execute a script/function?
                Jerry62712 Level 1

                Anyone?  FlexUI?

                • 5. Re: How do I execute a script/function?
                  Gregory Lafrance Level 6

                  Here is an example:

                   

                  I create a file test.as containing a function myFunc() which simply pops up an alert.

                  Then I include the file in my main app, and call the function at creationComplete event.

                   

                  ---------------------------------- test.as ---------------------------------

                  import mx.controls.Alert;
                  public function myFunc():void{
                    mx.controls.Alert.show("function called");
                  }
                  

                   

                   

                  --------------------------- main.mxml ----------------------------------

                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                    creationComplete="myFunc();">
                    <mx:Script>
                      <![CDATA[
                        include "test.as";
                      ]]>
                    </mx:Script>
                  </mx:Application>
                  


                  If this post answers your question or helps, please mark it as such.


                  Greg Lafrance - Flex 2 and 3 ACE certified

                  www.ChikaraDev.com

                  Flex Training and Support Services

                  • 6. Re: How do I execute a script/function?
                    Jerry62712 Level 1

                    Thanks for getting back on this.  While still untested, I did find a solution.

                     

                    The problem was a component doesn't have an application tag to put the "creationCompleted" action into.  Further, I was not able to get the option to popup with code assist anywhere else.  Naturally, that does popup now with the canvas object so it is a mystery why it didn't when I beat it to death yesterday.

                     

                    Anyway, I was able to get the syntax correct and have added that to each of the six components.  Next I'll have to test it with JAWS to see if it does what I expect it to.

                     

                    Coming soon  -  pictures of what you will look like in 30 years.  I mentioned that you look just like I did back in the day.  But I couldn't get a flash drive to work with my computer so I could copy some images.  It turns out I get a device conflict, but adding a second flash drive works as it is in a new space as the first one occupies and crashes the first one.  The results is that if I'm careful I can use that second drive to actually move stuff around.