9 Replies Latest reply on Jul 26, 2013 3:26 PM by pauland

    Basic Question:  How to call a Class in mxml and Run it

    markerline Champion

      Hi.  I'm doing my bit to try and learn Away3D.  I have successfully run the application from Flash Builder 4.0 standard as an ActionScript Project.  However now I want to run it as a Flex Project which gives me the ability to run it as a desktop application via AIR.

       

      I have the following code:  (Why is my code not executing the SphereDemo.as Class which is supposed to be able to display a Poly Sphere on the viewport?)

       

       

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

      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"

                             xmlns:s="library://ns.adobe.com/flex/spark"

                             xmlns:mx="library://ns.adobe.com/flex/mx"

                             creationComplete="runMe();">

          <fx:Declarations>

              <!-- Place non-visual elements (e.g., services, value objects) here -->

          </fx:Declarations>

          <fx:Script>

              <![CDATA[

                  public function runMe():void

                  {

                      var mySphere:SphereDemo = new SphereDemo();

                      mySphere;

                      //SphereDemo;

                  }

                 

              ]]>

          </fx:Script>

      </s:WindowedApplication>

        • 1. Re: Basic Question:  How to call a Class in mxml and Run it
          markerline Champion

          As a note, I'm also getting a #1009 Null Object Reference error when I run this application as it is above.

          • 2. Re: Basic Question:  How to call a Class in mxml and Run it
            markerline Champion

            Here is the complete error message:

             

            TypeError: Error #1009: Cannot access a property or method of a null object reference.

                at AwayAS/initEngine()[C:\Users\root\Adobe Flash Builder 4.6\AwayMXML\src\AwayAS.as:27]

                at AwayAS()[C:\Users\root\Adobe Flash Builder 4.6\AwayMXML\src\AwayAS.as:17]

                at SphereDemo()[C:\Users\root\Adobe Flash Builder 4.6\AwayMXML\src\SphereDemo.as:8]

                at AwayMXML()[C:\Users\root\Adobe Flash Builder 4.6\AwayMXML\src\AwayMXML.mxml:12]

                at _AwayMXML_mx_managers_SystemManager/create()[_AwayMXML_mx_managers_SystemManager.as:51]

                at mx.managers.systemClasses::ChildManager/initializeTopLevelWindow()[E:\dev\4.y\frameworks\ projects\framework\src\mx\managers\systemClasses\ChildManager.as:311]

                at mx.managers::SystemManager/initializeTopLevelWindow()[E:\dev\4.y\frameworks\projects\fram ework\src\mx\managers\SystemManager.as:3057]

                at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::kickOff()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:2843]

                at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::preloader_completeHandler()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:2723]

                at flash.events::EventDispatcher/dispatchEventFunction()

                at flash.events::EventDispatcher/dispatchEvent()

                at mx.preloaders::Preloader/timerHandler()[E:\dev\4.y\frameworks\projects\framework\src\mx\p reloaders\Preloader.as:542]

                at flash.utils::Timer/_timerDispatch()

                at flash.utils::Timer/tick()

            • 3. Re: Basic Question:  How to call a Class in mxml and Run it
              markerline Champion

              and here is the new mxml code:

               

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

              <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"

                                     xmlns:s="library://ns.adobe.com/flex/spark"

                                     xmlns:mx="library://ns.adobe.com/flex/mx"

                                     xmlns="*"

                                     creationComplete="runMe()">

                  <fx:Declarations>

                      <!-- Place non-visual elements (e.g., services, value objects) here -->

                  </fx:Declarations>

                  <fx:Script>

                      <![CDATA[

                          public var mySphere:SphereDemo = new SphereDemo();

                         

                          public function runMe():void

                          {

                              mySphere=new SphereDemo();

                              addChild(mySphere as DisplayObject);

                          }

                      ]]>

                  </fx:Script>

              </s:WindowedApplication>

              • 4. Re: Basic Question:  How to call a Class in mxml and Run it
                markerline Champion

                it appears by the error 1009 that the mxml problem is with line 12 "public var mySphere:SphereDemo = new SphereDemo();"

                 

                This tutorial is several years old but it's still relevant as Adobe has just released Away Builder as part of its Gaming SDK using AwayBuilder-dot-com's toolset.

                • 5. Re: Basic Question:  How to call a Class in mxml and Run it
                  pauland Champion

                  It appears by the error 1009 that the mxml problem is with line 12 "public var mySphere:SphereDemo = new SphereDemo();"

                   

                  No,  the error is at C:\Users\root\Adobe Flash Builder 4.6\AwayMXML\src\AwayAS.as line 27.

                   

                  There is a problem in the AwayAS.as code.

                  • 6. Re: Basic Question:  How to call a Class in mxml and Run it
                    markerline Champion

                    Thanks for replying.  You're right I am by no means experienced in Flex/Flash Builder but it should seem strange that the same exact code can compile and run as an ActionScript Project but not as a Flex Project using mxml.  Don't you find that puzzling?

                    • 7. Re: Basic Question:  How to call a Class in mxml and Run it
                      pauland Champion

                      It's surprising, but there can be any number of reasons.

                       

                      I was surprised that  you weren't able to interpret the stack trace to see where the error was.

                       

                      The debugger is your friend.

                      1 person found this helpful
                      • 8. Re: Basic Question:  How to call a Class in mxml and Run it
                        markerline Champion

                        I've used the debugger in previous scenarios with varying degrees of success, sometimes great success.  However this time I wasn't quite sure where to begin since I thought my code for mxml was all screwed up.  And the debugger as I just ran it actually did tell me that I couldn't use addChild and I had to use addElement instead.  But that fix of code didn't solve other bugs that popped up at which I am stumped at the moment.  Perhaps I will find a solution online to the problem after using addElement(mySphere as IVisualElement).  I also imported all of the classes that were in the original as document with the exception of the Sphere class.  I thought I wouldn't have to import that since code-completion popped up when trying to add and type (type as in kind, not type with the keyboard) the Sphere variable.

                        • 9. Re: Basic Question:  How to call a Class in mxml and Run it
                          pauland Champion

                          I think this is a bad way to try and understand how MXML works.

                           

                          Get used to working with MXML, then look at this project once you understand what is going on.

                           

                          Just getting it to compile is no guarantee of success - as you have found.