4 Replies Latest reply on Feb 9, 2011 2:01 PM by Olav Martin Kvern

    How to access elements in main.mxml from ActionScript file?

    MChan4WTBTS

       

      I am having difficulties creating a panel using the Extension Builder SDK. It seems that all the examples explain how to control a CS5 document using a panel, but I have not found any examples of how to control the elements of the panel via the ActionScript.   By the way we are using CS Extension Builder SDK with Flash Builder 4.  Here is a simple example of were I am getting stuck.

       

       

      I create a Extension builder project for a PS panel named: "CSExtensionTest".  In the main.mxml file a create a button with id="btnPSCode".

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      ****************************************************************************************** *****************************************

      File:

       

       

       

       

       

       

      main.mxml

      ****************************************************************************************** *****************************************

       

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

       

       

      <mx:Application

       

       

       

       

      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" historyManagementEnabled="false">

       

           

       

       

      <mx:Script>

       

                   <![CDATA[

       

                          [

       

       

      Bindable]

                          private var hostName:String = HostObject.mainExtension;

                        

                   ]]>

            </mx:Script>

       

           

       

       

      <mx:VBox height="100%" width="100%" verticalAlign="middle" horizontalAlign="center">

       

                  

       

       

      <mx:Button id="btnPSCode" label="Run PS code" click="CSExtensionTestPhotoshop.run()" enabled="{hostName.indexOf('photoshop') > -1}"/>

       

                  

       

       

      <mx:Button id="btnJSXCode" label="Run JSX code" click="CSExtensionTestJSX.run()"/>

       

           

       

       

      </mx:VBox>

      </mx:Application>

       

       

      ****************************************************************************************** *****************************************

       

       

       

       

       

       

      How can i get access to the properties of this element in the CSExtensionTesJSX.as file?

       

       

       

       

       

      ****************************************************************************************** *****************************************

      File:

       

       

      CSExtensionTesJSX.as

       

      ****************************************************************************************** *****************************************

       

       

      package

       

       

       

       

       

       

       

      {

       

       

       

       

      import com.adobe.csxs.core.CSXSInterface;

          

       

       

      import com.adobe.csxs.core.csxs_internal;

          

       

       

      import com.adobe.csxs.types.SyncRequestResult;

          

       

       

       

      import mx.binding.utils.BindingUtils;

          

       

       

      import mx.core.ButtonAsset;

          

       

       

      import mx.core.mx_internal;

          

       

       

      import mx.utils.object_proxy;

       

       

       

       

       

      public class CSExtensionTestJSX

            {    

       

       

       

      public static function run():void

                   {

       

       

       

      var myCSXS:CSXSInterface = CSXSInterface.getInstance();

                        

       

       

      var result:SyncRequestResult = CSXSInterface.instance.evalScript("jsxFunction");

       

                          btnPSCode.enabled = false;

       

       

       

       

                   }

            }

      }

       

       

       

       

       

       

      ****************************************************************************************** *****************************************

       

       

       

      I'm getting this error:

      image001.png

       

       

       

       

       

       

       

      I had originally written a panel using a Flex Project and was able to access the properties of the elements of the main.mxml file directly.  It seems I can't do that anymore.  Am I missing something in the code?  Am I missing some type of library?  I'm sorry I am not very experienced in Adobe development, but we are trying to get more involved in developing plugins and extensions for CS5.  Any help will be greatly appreciated.

        • 1. Re: How to access elements in main.mxml from ActionScript file.
          david_a_clark Adobe Employee

          You need to pass a reference to your main mxml object into the run method. For example:

           

          main.mxml:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" historyManagementEnabled="false">
              <mx:Script>
                  <![CDATA[

           

                      [Bindable]
                      private var hostName:String = HostObject.mainExtension;
                     
                  ]]>
              </mx:Script>
              <mx:VBox height="100%" width="100%" verticalAlign="middle" horizontalAlign="center">
                  <mx:Button id="myButton" label="Run JSX code" click="testJSX.run(this)"/>
              </mx:VBox>
          </mx:Application>

           

          testJSX.as:

           

          package
          {
              import com.adobe.csxs.core.CSXSInterface;
              import com.adobe.csxs.types.SyncRequestResult;
             
              import mx.controls.Button;

           

              public class testJSX
              {   
                  public static function run(m:main):void
                  {
                      var result:SyncRequestResult = CSXSInterface.instance.evalScript("jsxFunction");   
                      var b:Button = m.myButton;
                  }
              }
          }

           

          HTH.

          • 2. Re: How to access elements in main.mxml from ActionScript file.
            MChan4WTBTS Level 1

            Thank you David for your quick response.  I really appreciate it.  It totally makes sense, but I'm still getting an error with the example you provided.

             

            I am getting this error on the statement:   var b:Button = m.myButton;

             

            Resource Description Path Location Type

            CSExtensionTestJSX.as 1120: Access of undefined property m. /CSExtensionTest/src line 24 Flex Problem

             

             

            Sorry for my inexperience in this platform.  Hoping to get better at it.  Again Thank you.

            • 3. Re: How to access elements in main.mxml from ActionScript file.
              MChan4WTBTS Level 1

              Opps... My fault.  Just figured out waht was missing.

               

              I forgot to enter the following on the funciton line.

               

              public static function run(m:main):void

               

               

              Again Thank you.

              • 4. Re: How to access elements in main.mxml from ActionScript file.
                Olav Martin Kvern Level 3

                Hi MChan4WTBTS,

                 

                When you're responding to a click event, as in David's example, you can also just pass the event. The event.target will be a reference to the button itself.

                 

                You can find some examples of this on the CS SDK blog, at:

                 

                http://blogs.adobe.com/cssdk/

                 

                Thanks,

                 

                Ole