2 Replies Latest reply on Apr 6, 2010 7:22 PM by Harry Kunz

    Document Class

    Harry Kunz Level 4

      I'm new to flex. I've explored it for a day. Since the main document is XML, i was wondering how i can create a centralized code base, like a document class to start my code execution. Instead of placing my code into an <fx script tag. Any best practices i should use? I'm using a Trial version of Flash Builder 4.

        • 1. Re: Document Class
          GordonSmith Level 4

          MXML files are just another way to write ActionScript classes. For example, if you write MyApp.mxml as

           

          <s:Applicaton>

              <fx:Script>

                  public var foo:int = 3;

                  public function doSomething():void

                  {

                      trace(foo);

                  }

              </fx:Script>

          </s:Application>

           

          then this corresponds to the ActionScript class

           

          public class MyApp extends spark.controls.Application

          {

              public var foo:int = 3;

            

              public function doSomething():void

              {

                  trace(foo);

              }

          }

           

          However, writing the app as an MXML file makes the compiler autogenerate some extra code, such as for initializing CSS styles, that is necessary for the app to run correctly.

           

          Gordon Smith

          Adobe Flex SDK Team

          1 person found this helpful
          • 2. Re: Document Class
            Harry Kunz Level 4

            Thank you for your response! i see, i see. So this first MXML file generated upon project creation, is it considered the document class? Can i instantiate an instance of another class inside the <fx:script> tag and pass a "this" to the constructor? What is the type of "this" inside that class? How can i create a script that automatically runs as the init script? I'm trying to implement the MVC framework in flex.