[Laszlo-checkins] r10686 - in openlaszlo/trunk/WEB-INF/lps: lfc/kernel/swf9 server/src/org/openlaszlo/sc

dda@openlaszlo.org dda at openlaszlo.org
Wed Aug 13 14:25:24 PDT 2008


Author: dda
Date: 2008-08-13 14:25:20 -0700 (Wed, 13 Aug 2008)
New Revision: 10686

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LFCApplication.as
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9External.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9ParseTreePrinter.java
Log:
Change 20080813-dda-W by dda at lester.local on 2008-08-13 11:27:57 EDT
    in /Users/dda/laszlo/src/svn/openlaszlo/trunk-b
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: SWF9: change top level application class inheritance

New Features:

Bugs Fixed: LPP-6781 (swf9 global confusion: x, y, declared as Number?)

Technical Reviewer: ptw (pending)
QA Reviewer: (pending)
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
    This changeset changes the inheritance structure so that the LzApplication class
    (containing user code) does not indirectly inherit from the as3 Sprite class.
    Sprite has data members 'x', 'y' (and several others) that would otherwise pollute
    the user's application namespace and prevent the use of these as variable names.

    However, a Sprite-inherited class is needed as the top level class that is executed
    in the flex program.  The solution is to leave LzApplication in place as the 'holder'
    for user code, but to create the LzApplication from a barebones Sprite-inherited class,
    that we call 'LzSpriteApplication'.

    The barebones generated class is this:

      public class LzSpriteApplication extends Sprite { 
         private var app:LzApplication; 
         public function LzSpriteApplication() { 
            app = new LzApplication(this); 
         } 
      } 

    and the LzApplication/LFCApplication constructor gets the sprite and makes it
    available for use as needed.

Tests:
    SWF8,DHTML: smokecheck, weather, lzpix
    SWF9: hello, weather, lzpix, application reported in LPP-6781



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LFCApplication.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LFCApplication.as	2008-08-13 21:14:13 UTC (rev 10685)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LFCApplication.as	2008-08-13 21:25:20 UTC (rev 10686)
@@ -9,7 +9,7 @@
   * @author Henry Minsky <hminsky at laszlosystems.com>
   */
 
-public class LFCApplication extends Sprite {
+public class LFCApplication {
 
     // This serves as the superclass of DefaultApplication, currently that is where
     // the compiler puts top level code to run.
@@ -25,17 +25,25 @@
     import flash.text.Font;
     }#
 
+    // The application sprite
+    public var _sprite:Sprite;
 
+    public function addChild(child:DisplayObject):DisplayObject {
+       _sprite.addChild(child);
+    }
+
     // Allow anyone access to the stage object (see ctor below)
     public static var stage:Stage = null;
 
     // Allow anyone access to write to the debugger
     public static var write:Function;
 
-    public function LFCApplication () {
+    public function LFCApplication (sprite:Sprite) {
 
+       _sprite = sprite;
+
         // Allow anyone to access the stage object
-        LFCApplication.stage = this.stage;
+        LFCApplication.stage = _sprite.stage;
         LFCApplication.write = this.write;
 
         // trace("LFCApplication.stage = " + LFCApplication.stage);

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9External.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9External.java	2008-08-13 21:14:13 UTC (rev 10685)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9External.java	2008-08-13 21:25:20 UTC (rev 10686)
@@ -649,20 +649,17 @@
       cmd.add("-include-classes");
     }
     
-    for (Iterator iter = tunits.iterator(); iter.hasNext(); ) {
-      TranslationUnit tunit = (TranslationUnit)iter.next();
-      
-      // For the application, we just list the main .as file
+    if (buildSharedLibrary) {
       // For a library, we list all the classes.
-      if (!buildSharedLibrary) {
-        if (tunit.isMainTranslationUnit()) {
-          cmd.add(workdir.getPath() + File.separator + tunit.getName()+".as");
-        }
-      }
-      else {
+      for (Iterator iter = tunits.iterator(); iter.hasNext(); ) {
+        TranslationUnit tunit = (TranslationUnit)iter.next();
         cmd.add(tunit.getName());
       }
     }
+    else {
+      // For the application, we just list one .as file
+      cmd.add(workdir.getPath() + File.separator + SWF9Generator.EXEC_APP_CLASSNAME + ".as");
+    }
     
     execCompileCommand(cmd, workdir.getPath(), tunits, outfilename);
     return getBytes(outfilename);

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java	2008-08-13 21:14:13 UTC (rev 10685)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java	2008-08-13 21:25:20 UTC (rev 10686)
@@ -37,6 +37,9 @@
   /** The user 'main' class, which extends LFCApplication */
   public final static String MAIN_APP_CLASSNAME = "LzApplication";
 
+  /** The top level class executed first, it creates a LzApplication object */
+  public final static String EXEC_APP_CLASSNAME = "LzSpriteApplication";
+
   /** The LFC 'main' class, which extends nothing */
   public final static String MAIN_LIB_CLASSNAME = "LFCApplication";
 
@@ -575,6 +578,10 @@
       } else {
         source += "public class " + SWF9Generator.MAIN_APP_CLASSNAME +
         " extends " +  SWF9Generator.MAIN_LIB_CLASSNAME + " {\n " + imports + "}\n";
+        source += "public class " + SWF9Generator.EXEC_APP_CLASSNAME +
+        " extends Sprite {\n " + imports + "var app:LzApplication;\n" +
+        " function " + SWF9Generator.EXEC_APP_CLASSNAME + "() {" +
+        " app = new LzApplication(this);}}\n";
       }
     }
     return source;

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9ParseTreePrinter.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9ParseTreePrinter.java	2008-08-13 21:14:13 UTC (rev 10685)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9ParseTreePrinter.java	2008-08-13 21:25:20 UTC (rev 10686)
@@ -244,7 +244,8 @@
     sb.append("{\n");
     sb.append(annotateInsertStream(CLASS_LEVEL_STREAM));
     if (classnm.equals(mainClassName) && !islib) {
-      sb.append("public function " + mainClassName + "() {\n");
+      sb.append("public function " + mainClassName + "(sprite:Sprite) {\n");
+      sb.append("super(sprite);\n");
       sb.append(annotateInsertStream(MAIN_CONSTRUCTOR_STREAM));
       sb.append("}\n");
     }



More information about the Laszlo-checkins mailing list