Author: hqm
Date: 2007-12-05 08:11:31 -0800 (Wed, 05 Dec 2007)
New Revision: 7454
Modified:
openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/TestApp.as
Log:
checkpoint lzsprite
Modified: openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
2007-12-05 14:00:35 UTC (rev 7453)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
2007-12-05 16:11:31 UTC (rev 7454)
@@ -38,10 +38,26 @@
public var text:String = null;
public var clip:Boolean = false;
public var stretches:String = null;
- public var resourceWidth:Number = 0;
- public var resourceHeight:Number = 0;
+ public var resourcewidth:Number = 0;
+ public var resourceheight:Number = 0;
public var isroot:Boolean = false;
+ public var resourceLoaded:Boolean = false;
+ public var resourceURL:String = null;
+
+ //@field Boolean _setrescwidth: If true, the view does not set its
+ //resource to the width given in a call to
+ //<method>setAttribute</method>. By default, views do not scale their
+ //resource
+ public var _setrescwidth:Boolean = false;
+
+ //@field Boolean _setrescheight: If true, the view does not set its
+ //resource to the height given in a call to
+ //<method>setAttribute</method>. By default, views do not scale their
+ //resource
+ public var _setrescheight:Boolean = false;
+
+
public function LzSprite (... initargs) {
// owner:*, isroot:Boolean
if (initargs.length == 2) {
@@ -92,11 +108,12 @@
o Uses the resourceload callback method when the resource finishes
loading
*/
public function setSource (url:String):void {
+ this.resourceURL = url;
imgLoader = new Loader();
this.addChildAt(imgLoader, IMGDEPTH);
var cl:LoaderInfo = imgLoader.contentLoaderInfo;
- cl.addEventListener(flash.events.HTTPStatusEvent.HTTP_STATUS,
loaderEventHandler);
- cl.addEventListener(flash.events.IOErrorEvent.IO_ERROR,
loaderEventHandler);
+ cl.addEventListener(HTTPStatusEvent.HTTP_STATUS, loaderEventHandler);
+ cl.addEventListener(IOErrorEvent.IO_ERROR, loaderEventHandler);
cl.addEventListener(Event.COMPLETE, loaderEventHandler);
cl.addEventListener(Event.INIT, loaderInitHandler);
@@ -122,7 +139,28 @@
public function loaderEventHandler(event:Event):void {
var loader:Loader = Loader(event.target.loader);
var info:LoaderInfo = LoaderInfo(loader.contentLoaderInfo);
- trace(event);
+ if (event.type == Event.COMPLETE) {
+ this.resourceLoaded = true;
+ // Apply stretch if needed, now that we know the asset
dimensions.
+ this.applyStretchResource();
+ if (this.owner != null) {
+ this.owner.resourceload({
+ width: loader.width,
+ height: loader.height,
+ sprite: this,
+ resource: this.resourceURL,
+ // When would we want skiponload to be true??
+ skiponload: false});
+ }
+ } else if (event.type == IOErrorEvent.IO_ERROR) {
+ // TODO [hqm 2007-12] is this the right event type? Should we be
looking
+ // at HTTP_STATUS event error codes also?
+ this.resourcewidth = 0;
+ this.resourceheight = 0;
+ if (this.owner != null) {
+ this.owner.resourceloaderror( event );
+ }
+ }
}
@@ -152,7 +190,8 @@
// libraries. There *is* an mx.controls.Button class,
// but I haven't figured out how to instantiate it and
// am not sure if it is more of a performance drain than
- // just using this alpha=0 sprite.
+ // just using this alpha=0 sprite. Not sure we want to
+ // use the higher level flex components lib anyway.
cb.graphics.beginFill(0xffffff);
@@ -213,6 +252,7 @@
o Sets the visibility of the sprite
*/
public function setVisible( visibility:Boolean ):void {
+ this.visible = visibility;
}
@@ -294,12 +334,36 @@
o Causes the sprite to stretch its resource along axes, either
'width' 'height' or 'both' so the resource is the same size as the sprite along
those axes.
o If axes is not 'width', 'height' or 'both', the resource is sized
to its natural/default size, rather than the sprite's size
*/
- public function stretchResource( axes:String ):void {
-
+ public function stretchResource( xory:String ):void {
+ trace("stretchResource imgLoader="+imgLoader);
+ if ( xory == null || xory == "x" || xory=="width" || xory=="both" ){
+ this._setrescwidth = true;
+ }
+ if ( xory == null || xory == "y"|| xory=="height" || xory=="both" ){
+ this._setrescheight = true;
+ }
+ this.applyStretchResource();
}
+ public function applyStretchResource():void {
+ if (this.resourceLoaded) {
+ if (this._setrescwidth) {
+ this.resourcewidth = imgLoader.width;
+ this.scaleX = this.lzwidth / this.resourcewidth;
+ } else {
+ this.scaleX = 1.0;
+ }
+ if (this._setrescheight) {
+ this.resourceheight = imgLoader.height;
+ this.scaleY = this.lzheight / this.resourceheight;
+ } else {
+ this.scaleY = 1.0;
+ }
+ }
+ }
+
/** destroy( Boolean:recursive )
o Causes the sprite to destroy itself
o if recursive is true, the sprite destroys all its children as well
@@ -336,6 +400,9 @@
o Brings this sprite to the front of its siblings
*/
public function bringToFront ():void {
+ if (!this.isroot) {
+ parent.setChildIndex(this, parent.numChildren-1);
+ }
}
@@ -343,9 +410,11 @@
o Sends this sprite to the back of its siblings
*/
public function sendToBack():void {
+ if (!this.isroot) {
+ parent.setChildIndex(this, 0);
+ }
}
-
/** setStyleObject( Object:style )
o Sets the style object of the sprite
*/
Modified: openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/TestApp.as
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/TestApp.as
2007-12-05 14:00:35 UTC (rev 7453)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/TestApp.as
2007-12-05 16:11:31 UTC (rev 7454)
@@ -18,6 +18,8 @@
public class TestApp extends Sprite {
public function TestApp () {
+ /*
+
//stage.addEventListener(MouseEvent.CLICK, clickListener);
var sprite1:* = new LzSprite(null, false);
@@ -79,17 +81,46 @@
sprite5.addEventListener(MouseEvent.MOUSE_DOWN, describeSprite) ;
+*/
+
+
// Test 'stretches'
- var sprite6:LzSprite = new LzSprite(null, false);
+
+ var sprite6:LzSprite = new LzSprite(null, false);
+ sprite6.owner = this;
sprite6.setX(0);
- sprite6.setY(400);
- sprite6.setSource("picture.jpg");
+ sprite6.setY(0);
sprite6.setWidth(100);
sprite6.setHeight(50);
- sprite6.setStretches("both");
+ sprite6.stretchResource("both");
+ sprite6.setSource("picture.jpg");
+ sprite6.addEventListener(MouseEvent.MOUSE_DOWN, bringToFront) ;
addChild(sprite6);
+ // Test bringToFront, sendToBack
+
+ var sprite7:LzSprite = new LzSprite(null, false);
+ sprite7.owner = this;
+ sprite7.setX(0);
+ sprite7.setY(0);
+ sprite7.setWidth(100);
+ sprite7.setHeight(100);
+ sprite7.setSource("logo.swf");
+ addChild(sprite7);
+
}
+
+ public function bringToFront(event:MouseEvent):void {
+ event.target.parent.bringToFront();
+ }
+
+ // emulating callback of lzview
+ public function resourceload(info:Object):void {
+ //info.sprite.stretchResource("both");
+ trace("resource loaded " +info);
+ }
+
+
public function describeSprite(event:MouseEvent):void {
trace('clicked on sprite', event);
}
_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins