[Laszlo-checkins] r8524 - in openlaszlo/trunk: WEB-INF/lps/lfc/kernel/swf9 WEB-INF/lps/lfc/services WEB-INF/lps/lfc/services/platform/swf9 WEB-INF/lps/lfc/views lps/components/base lps/components/lz test/swf9

hqm@openlaszlo.org hqm at openlaszlo.org
Wed Apr 2 10:52:28 PDT 2008


Author: hqm
Date: 2008-04-02 10:52:23 -0700 (Wed, 02 Apr 2008)
New Revision: 8524

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
   openlaszlo/trunk/WEB-INF/lps/lfc/services/LzFocus.lzs
   openlaszlo/trunk/WEB-INF/lps/lfc/services/platform/swf9/LzKeys.js
   openlaszlo/trunk/WEB-INF/lps/lfc/views/LaszloCanvas.js
   openlaszlo/trunk/lps/components/base/basebutton.lzx
   openlaszlo/trunk/lps/components/base/basecomponent.lzx
   openlaszlo/trunk/lps/components/lz/checkbox.lzx
   openlaszlo/trunk/test/swf9/checkbox.lzx
Log:
Change 20080402-hqm-2 by hqm at badtzmaru.local on 2008-04-02 13:50:48 EDT
    in /Users/hqm/openlaszlo/trunk
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: misc swf9 kernel and component changes to make checkbox example compile

New Features:

Bugs Fixed:

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

Documentation:

Release Notes:

Details:
    
+ changes to swf9 multi-frame resource handling

+ declare some optional args for methods in button component that can get
called by sendEvent

+ turn swf9 LzKeys into a real static class with static methods and vars


Tests:



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as	2008-04-02 17:39:43 UTC (rev 8523)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as	2008-04-02 17:52:23 UTC (rev 8524)
@@ -44,6 +44,8 @@
       public var resourceheight:Number = 0;
       public var isroot:Boolean = false;
 
+      var resourceObj:DisplayObject = null;
+
       public var resourceLoaded:Boolean = false;
       public var resourceURL:String = null;
 
@@ -121,69 +123,87 @@
           o Calls setSource to load media if resource is an URL
           o Uses the resourceload callback method when the resource finishes loading 
       */
-public function setResource (r:String):void {
-    if (this.resource == r) return;
-    if ( r.indexOf('http:') == 0 || r.indexOf('https:') == 0){
-        this.skiponload = false;
-        this.setSource( r );
-        this.resource = r;
-        return;
-    }
+      public function setResource (r:String):void {
+          if (this.resource == r) return;
+          if ( r.indexOf('http:') == 0 || r.indexOf('https:') == 0){
+              this.skiponload = false;
+              this.setSource( r );
+              this.resource = r;
+              return;
+          }
+          // LzResourceLibrary.lzcheckbox_rsrc =
+          //  {frames: [__embed_lzasset_lzcheckbox_rsrc_0,
+          //           __embed_lzasset_lzcheckbox_rsrc_1, ....], width: 15, height: 14};
 
-    this.resource = r;
+          // or
+          // LzResourceLibrary.lzfocusbracket_bottomright_shdw =
+          // {ptype: ("sr" || "ar" ),
+          //  assetclass: __embed_lzasset_lzfocusbracket_bottomright_shdw,
+          // frames: ["lps/components/lz/resources/focus/focus_bot_rt_shdw.png"], width: 9, height: 9};
 
-    // look up resource name in LzResourceLibrary
-    // LzResourceLibrary is in the format:
-    // LzResourceLibrary.lzscrollbar_xthumbleft_rsc={ptype:"ar"||"sr",frames:["lps/components/lz/resources/scrollbar/scrollthumb_x_lft.png"],width:1.0,height:12.0}
 
-    var res = LzResourceLibrary[r];
-    if (! res) {
-        if ($debug) {
-            Debug.warn('Could not find resource', r);
-        }
-        return;
-    }
+          this.resource = r;
 
-    // TODO [hqm 2008-01] How do we deal with multiframe embedded resources??
-    if ('assetclass' in res) {
-        var assetclass = res['assetclass'];
-        var asset:DisplayObject = new assetclass();
-        addChild(asset);
-        return;
-    }
+          var res = LzResourceLibrary[r];
+          if (! res) {
+              if ($debug) {
+                  Debug.warn('Could not find resource', r);
+              }
+              return;
+          }
 
+          this.resourceWidth = res.width;
+          this.resourceHeight = res.height;
+          this.skiponload = true;
 
-    var urls = res.frames;
+          // TODO [hqm 2008-01] How do we deal with multiframe embedded resources??
+          if ('assetclass' in res) {
+              var assetclass = res['assetclass'];
+              var asset:DisplayObject = new assetclass();
 
-    //this.owner.onimload.sendEvent({width: res.width, height: res.height});
-    this.resourceWidth = res.width;
-    this.resourceHeight = res.height;
-    this.skiponload = true;
+              // remove previous asset, and display new one
+              if (this.resourceObj != null) {
+                  removeChild(this.resourceObj);
+              }
+              this.resourceObj = asset;
 
-    //Update the view's totalframes
-    this.owner.setTotalFrames (urls.length);
+              addChild(asset);
+              return;
+          }
 
-    // It could be a multi-frame resource. Take first frame.
-    var url = urls[0];
-    if (url) {
-        this.baseurl = '';
-        if (res.ptype) {
-            if (res.ptype == 'sr') {
-                this.baseurl = lzOptions.ServerRoot + '/';
-            }
-            //Debug.write('ptype', res.ptype, this.baseurl);
-        }
+          var urls = res.frames;
 
-        this.frames = urls;
-        this.__preloadFrames();
-        this.setSource(url, true);
-    } else {
-        this.setSource(r, true);
-    }
-    //Debug.info('setResource ', r, this.frames)
-}
+          //Update the view's totalframes
+          this.owner.setTotalFrames (urls.length);
 
+          // It could be a multi-frame resource. Take first frame.
+          var url = urls[0];
+          if (url is Class) {
+              // resource is an embedded asset class
+              var asset:DisplayObject = new url();
+              // remove previous asset, and display new one
+              if (this.resourceObj != null) {
+                  removeChild(this.resourceObj);
+              }
+              this.resourceObj = asset;
+              addChild(asset);
+          } else {
+              // resource is a string, so it's an URL
+              this.baseurl = '';
+              if (res.ptype) {
+                  if (res.ptype == 'sr') {
+                      this.baseurl = lzOptions.ServerRoot + '/';
+                  }
+                  //Debug.write('ptype', res.ptype, this.baseurl);
+              }
 
+              this.frames = urls;
+              this.__preloadFrames();
+              this.setSource(url, true);
+          }
+      }
+
+
       public var imgLoader:Loader;
       private var IMGDEPTH:int = 0;
 
@@ -194,6 +214,7 @@
       public function setSource (url:String, cache = null, headers = null):void {
           this.resourceURL = url;
           imgLoader = new Loader();
+          this.resourceObj = imgLoader;
           this.addChildAt(imgLoader, IMGDEPTH);
           var info:LoaderInfo = imgLoader.contentLoaderInfo;
           info.addEventListener(Event.INIT,       loaderInitHandler);
@@ -433,8 +454,10 @@
           trace('LzSprite.getColor not yet implemented');
       }
 
+      public function setColorTransform(o=null) {
+          trace('LzSrpite.setColorTransform not yet implemented');
+      }
 
-
       /** setBGColor( String/Number:color )
           o Sets the background color of the sprite
           o Can be a number (0xff00ff):void or a string ('#ff00ff'):void 
@@ -460,6 +483,8 @@
           o Plays from the current frame if framenumber is null 
       */
       public function play( framenumber:* ):void {
+          // TODO [hqm 2008-04] what to do about playing movies? 
+          stop(framenumber);
       }
 
 
@@ -468,6 +493,28 @@
           o Stops at the current frame if framenumber is null 
       */
       public function stop( framenumber:*, rel:* = null ):void {
+          // TODO [hqm 2008-04-02] This discards the current asset and
+          // instantiates a new asset from the multiframe asset
+          // list. It seems wasteful to do this, we ought to keep a
+          // table of the instantiated DisplayObject for each
+          // frameframe, and just add and remove them from the display list
+          // with addChild and removeChild.
+
+          var res = LzResourceLibrary[this.resource];
+          var frames = res.frames;
+
+          trace('stop ',framenumber);
+          trace('   rel=', rel);
+          trace('   this.resource', this.resource, res, res.frames[framenumber]);
+          // remove previous asset, and display new one
+          if (this.resourceObj != null) {
+              removeChild(this.resourceObj);
+          }
+
+          var assetclass = frames[framenumber];
+          var asset:DisplayObject = new assetclass();
+          this.resourceObj = asset;
+          addChild(asset);
       }
 
 

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/services/LzFocus.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/services/LzFocus.lzs	2008-04-02 17:39:43 UTC (rev 8523)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/services/LzFocus.lzs	2008-04-02 17:52:23 UTC (rev 8524)
@@ -19,7 +19,7 @@
   * 
   * @shortdesc Handles keyboard focus.
   */
-class LzFocusClass {
+dynamic class LzFocusClass {
 
     /** Sent when the focus changes, with the argument being the view
      * that was just focused. If nothing is focussed, this event is sent with null.

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/services/platform/swf9/LzKeys.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/services/platform/swf9/LzKeys.js	2008-04-02 17:39:43 UTC (rev 8523)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/services/platform/swf9/LzKeys.js	2008-04-02 17:52:23 UTC (rev 8524)
@@ -34,37 +34,37 @@
   *
   * @shortdesc Keyboard input service.
   */
-dynamic public class LzKeysClass {
+dynamic public class LzKeys {
 
     /**
      * A hash where each of the keys that is currently 
      * down on the keyboard is set to true.
      * @type Object
      */
-    var downKeysHash = {};
+    static var downKeysHash = {};
 
     /**
      * An array of currently pressed key codes.
      * @type [Number]
      */
-    var downKeysArray = [];
-    var keycombos = {};
+    static var downKeysArray = [];
+    static var keycombos = {};
 
     /**
      * event sent when a key is pressed; sent with keycode 
      * for key that was pressed.
      */
-    var onkeydown = LzDeclaredEvent;
+    static var onkeydown = LzDeclaredEvent;
     /**
      * event sent whenever a key goes up; sent with keycode
      * for key that was let go.
      */
-    var onkeyup = LzDeclaredEvent;
-    var onmousewheeldelta = LzDeclaredEvent;
+    static var onkeyup = LzDeclaredEvent;
+    static var onmousewheeldelta = LzDeclaredEvent;
 
 
     /** @access private */
-    function __keyEvent ( delta, k, type ){
+    static static function __keyEvent ( delta, k, type ){
         //Debug.write('LzKeys.__keyEvent', delta, k, type);
         if (type == 'onkeydown') {
             gotKeyDown(k);
@@ -81,7 +81,7 @@
      * @param Number kC: The Flash keycode for the key that is down.
      * @param string info: if "extra" then ignore if you already got one
      */
-    function gotKeyDown ( kC, info = null ){
+    static function gotKeyDown ( kC, info = null ){
         if ( downKeysArray.length > 0 ){
             var badkeys = null;
 
@@ -135,7 +135,7 @@
      * @access private
      * @param Number kC: The Flash keycode for the key that was released.
      */
-    function gotKeyUp ( kC ){
+    static function gotKeyUp ( kC ){
 
         if (!downKeysHash[ kC ]) {
             // Debug.write("derived keyDown", kC);
@@ -161,7 +161,7 @@
      * @param String k: The name of the key to check for downness or an array of
      * key names (e.g. ['shift', 'tab']
      */
-    function isKeyDown ( k ){
+    static function isKeyDown ( k ){
         if (typeof(k) == "string") {
             return (downKeysHash[ keyCodes[ k.toLowerCase() ] ] == true);
         } else {
@@ -273,7 +273,7 @@
      * @param [String] kCArr: Array of strings indicating which keys constitute the
      * keycombo. This array may be in any order.
      */
-    function callOnKeyCombo ( d , kCArr ){
+    static function callOnKeyCombo ( d , kCArr ){
 
         var kcSorted = [];
         for (var i = 0; i < kCArr.length; i++ ){
@@ -301,7 +301,7 @@
      * @param [String] kCArr: An array of strings indicating which keys 
      * constituted the keycombo.
      */
-    function removeKeyComboCall ( d , kCArr ){
+    static function removeKeyComboCall ( d , kCArr ){
         var kcSorted = [];
         for (var i = 0; i < kCArr.length; i++ ){
             kcSorted.push( keyCodes[ kCArr[ i ].toLowerCase() ] );
@@ -325,7 +325,7 @@
     /**
      * @access private
      */
-    function enableEnter ( onroff ){
+    static function enableEnter ( onroff ){
         //Debug.write("enableEnter: "+onroff);
         // SWF-specific
         Debug.write('LzKeys.enableEnter not yet defined in swf9');
@@ -475,15 +475,13 @@
      * @field Number mousewheeldelta: the amount the mouse wheel last moved.  Use
      * onmousewheeldelta to learn when this value changes.
      */
-    var mousewheeldelta = 0;
+    static var mousewheeldelta = 0;
 
     /** @access private */
-    function __mousewheelEvent (d) {
+    static function __mousewheelEvent (d) {
         mousewheeldelta = d;
         if (onmousewheeldelta.ready) onmousewheeldelta.sendEvent(d);
     }
 
 }
 
-
-var LzKeys = new LzKeysClass ();

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/views/LaszloCanvas.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/views/LaszloCanvas.js	2008-04-02 17:39:43 UTC (rev 8523)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/views/LaszloCanvas.js	2008-04-02 17:52:23 UTC (rev 8524)
@@ -302,18 +302,19 @@
 function initDone (){
     //reorder initial subviews so preloaded stuff is first
     var sva = new Array;
+    var isv = this._lzinitialsubviews;
 
-    for ( var i = 0; i < this._lzinitialsubviews.length; i++ ){
-        if ( 'initimmediate' in this._lzinitialsubviews[ i ].attrs && 
-             this._lzinitialsubviews[ i ].attrs.initimmediate ){
-            sva.push( this._lzinitialsubviews[ i ] );
+    for ( var i = 0; i < isv.length; i++ ){
+        var isi = isv[i];
+        if ( isi['attrs'] && isi.attrs['initimmediate'] ){
+            sva.push( isi );
         }
     }
 
-    for ( var i = 0; i < this._lzinitialsubviews.length; i++ ){
-        if ( !('initimmediate' in this._lzinitialsubviews[ i ].attrs && 
-             this._lzinitialsubviews[ i ].attrs.initimmediate) ){
-            sva.push( this._lzinitialsubviews[ i ] );
+    for ( var i = 0; i < isv.length; i++ ){
+        var isi = isv[i];
+        if ( ! ( isi['attrs'] && isi.attrs['initimmediate'] ) ){
+            sva.push( isi );
         }
     }
 

Modified: openlaszlo/trunk/lps/components/base/basebutton.lzx
===================================================================
--- openlaszlo/trunk/lps/components/base/basebutton.lzx	2008-04-02 17:39:43 UTC (rev 8523)
+++ openlaszlo/trunk/lps/components/base/basebutton.lzx	2008-04-02 17:52:23 UTC (rev 8524)
@@ -112,7 +112,7 @@
        ]]> </method>
 
         <!--- When the space bar is down, basebutton shows its down state. -->
-        <method name="doSpaceDown">
+        <method name="doSpaceDown"  args="e=null">
             <![CDATA[
             if ( this._enabled) {
                 this.showDown();
@@ -121,7 +121,7 @@
         </method>
 
         <!--- When the space bar is up, basebutton shows its up state. -->
-        <method name="doSpaceUp">
+        <method name="doSpaceUp"  args="e=null">
             <![CDATA[
             if ( this._enabled) {
                 this.onclick.sendEvent();
@@ -131,14 +131,14 @@
         </method>
 
         <!--- Called by the button manager when this button is the default-->
-        <method name="doEnterDown">
+        <method name="doEnterDown"  args="e=null">
             if ( this._enabled ){
                 this.showDown( );
             }
         </method>
     
         <!--- Called by the button manager when this button is the default-->
-        <method name="doEnterUp">
+        <method name="doEnterUp"  args="e=null">
             if ( this._enabled ){
                 if ( this.onclick ){
                     this.onclick.sendEvent();

Modified: openlaszlo/trunk/lps/components/base/basecomponent.lzx
===================================================================
--- openlaszlo/trunk/lps/components/base/basecomponent.lzx	2008-04-02 17:39:43 UTC (rev 8523)
+++ openlaszlo/trunk/lps/components/base/basecomponent.lzx	2008-04-02 17:52:23 UTC (rev 8524)
@@ -131,30 +131,30 @@
         </method>
 
         <!--- @access private -->
-        <method name="_doMousedown"> 
+        <method name="_doMousedown" args="e=null"> 
         </method>
 
         <!--- Called if this component has the focus and the space bar goes 
               down -->
-        <method name="doSpaceDown">
+        <method name="doSpaceDown"  args="e=null">
             return false;
         </method>
 
         <!--- Called if this component has the focus and the space bar goes 
               up -->
-        <method name="doSpaceUp">
+        <method name="doSpaceUp"  args="e=null">
             return false;
         </method>
 
         <!--- Called if this component has the focus and the component
               has doesenter set to true and the enter key goes down -->
-        <method name="doEnterDown">
+        <method name="doEnterDown"  args="e=null">
             return false;
         </method>
 
         <!--- Called if this component has the focus and the component
               has doesenter set to true and the enter key goes up -->
-        <method name="doEnterUp">
+        <method name="doEnterUp"  args="e=null">
             return false;
         </method>
 
@@ -255,7 +255,7 @@
         </method>
 
         <!--- @access private -->
-        <method name="_usestyle">  
+        <method name="_usestyle" args="e=null">  
             <![CDATA[
             if (this._initcomplete && this['style'] && this.style.isinited) {
                 // note: in the case of lazy replication or if a component

Modified: openlaszlo/trunk/lps/components/lz/checkbox.lzx
===================================================================
--- openlaszlo/trunk/lps/components/lz/checkbox.lzx	2008-04-02 17:39:43 UTC (rev 8523)
+++ openlaszlo/trunk/lps/components/lz/checkbox.lzx	2008-04-02 17:52:23 UTC (rev 8524)
@@ -36,7 +36,7 @@
         </multistatebutton>
 
         <!--- toggles the value when the space bar is pressed while focused -->
-        <method name="doSpaceUp">
+        <method name="doSpaceUp"  args="e=null">
             <![CDATA[
             if ( this._enabled ) {
                this.setAttribute('value', !this.value);

Modified: openlaszlo/trunk/test/swf9/checkbox.lzx
===================================================================
--- openlaszlo/trunk/test/swf9/checkbox.lzx	2008-04-02 17:39:43 UTC (rev 8523)
+++ openlaszlo/trunk/test/swf9/checkbox.lzx	2008-04-02 17:52:23 UTC (rev 8524)
@@ -1,5 +1,14 @@
-<canvas width="800" height="600"> 
-  <checkbox id="foo">check me</checkbox>
+<canvas width="800" height="600" debug="false"> 
+  <checkbox name="foo"  >check me</checkbox>
+  <view y="100" width="20" height="20" bgcolor="green">
+    <attribute name="enable" value="true"/>
+  <handler name="onclick">
+    this.enable = !this.enable;
+    trace('enable = ', this.enable, 'foo.setEnabled(',this.enable,')');
+    parent.foo.setAttribute('enabled', this.enable);
+    setBGColor(this.enable ? 0x00ff00 : 0xff0000);
+  </handler>
+  </view>
 </canvas>
 <!-- * X_LZ_COPYRIGHT_BEGIN ***************************************************
 * Copyright 2001-2008 Laszlo Systems, Inc.  All Rights Reserved.              *



More information about the Laszlo-checkins mailing list