[Laszlo-checkins] r11331 - in openlaszlo/trunk/WEB-INF/lps/lfc/kernel: swf swf9
max@openlaszlo.org
max at openlaszlo.org
Thu Oct 2 19:45:58 PDT 2008
Author: max
Date: 2008-10-02 19:45:57 -0700 (Thu, 02 Oct 2008)
New Revision: 11331
Modified:
openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzSoundMC.as
openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
Log:
Change 20081002-maxcarlson-s by maxcarlson at Bank on 2008-10-02 19:21:11 PDT
in /Users/maxcarlson/openlaszlo/trunk-clean
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary: Add playback control for loaded movieclips
Bugs Fixed: LPP-6914 - Make playback controls work for swf9 animations
Technical Reviewer: andre.bargull at udo.edu
QA Reviewer: promanik
Doc Reviewer: (pending)
Details: LzSoundMC.as - Use canvas.framerate instead of hardcoded value.
LzSprite.as - Add __isinternalresource to track whether an internal resource is loaded. Warn if the loaded movie is an AVM1Movie and won't support playback controls. Otherwise, store a reference to the loader movieclip. Add updateFrames() method to handle frame updates. Update play() and stop() to deal with internal resources, loaded movieclips, and streaming audio appropriately.
Tests: Testcase at LPP-6914 runs consistently in swf8 and swf9.
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzSoundMC.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzSoundMC.as 2008-10-03 02:27:45 UTC (rev 11330)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzSoundMC.as 2008-10-03 02:45:57 UTC (rev 11331)
@@ -24,7 +24,6 @@
SoundMC.prototype._currentframe = 0;
SoundMC.prototype._framesloaded = 0;
SoundMC.prototype._totalframes = 0;
-SoundMC.prototype._fps = 30;
SoundMC.prototype.isaudio = true;
SoundMC.prototype.loadstate = 0;
@@ -36,7 +35,7 @@
if (direct != true && this._currentframe == this._totalframes) {
t = 0;
} else {
- var t = this._currentframe / this._fps;
+ var t = this._currentframe / canvas.framerate;
if (t < 0) t = 0;
}
this._sound.stop();
@@ -120,8 +119,8 @@
* @access private
*/
SoundMC.prototype.testPlay = function(ignore) {
- this._totalframes = Math.floor(this._sound.duration * .001 * this._fps);
- this._currentframe = Math.floor(this._sound.position * .001 * this._fps);
+ this._totalframes = Math.floor(this._sound.duration * .001 * canvas.framerate);
+ this._currentframe = Math.floor(this._sound.position * .001 * canvas.framerate);
this._framesloaded = Math.floor((this._sound.getBytesLoaded() / this._sound.getBytesTotal()) * this._totalframes)
//Debug.write('testPlay ', this._currentframe, this._totalframes, this._framesloaded);
}
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as 2008-10-03 02:27:45 UTC (rev 11330)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as 2008-10-03 02:45:57 UTC (rev 11331)
@@ -83,6 +83,9 @@
public var _setrescheight:Boolean = false;
private var __mousedown:Boolean = false;
+ // null if no resource is loaded, true if it's a compiled resource, and
+ // false if it's loaded from an external URL
+ private var __isinternalresource:* = null;
public static var capabilities:* = {
@@ -213,6 +216,7 @@
this.createResourceBitmap()
}
+ this.__isinternalresource = true;
this.resource = r;
// instantiate resource at frame 1
this.stop(1);
@@ -221,6 +225,7 @@
} else if (LzAsset.isSoundAsset(r)) {
// unload previous image-resource and sound-resource
this.unload();
+ this.__isinternalresource = true;
this.resource = r;
this.sound = new res['assetclass']() as Sound;
@@ -238,6 +243,7 @@
public var imgLoader:Loader;
+ public var loaderMC:MovieClip;
private var IMGDEPTH:int = 0;
/** setSource( String:url )
@@ -249,6 +255,8 @@
return;
}
+ this.__isinternalresource = false;
+
if (getFileType(url, filetype) == "mp3") {
// unload previous image-resource and sound-resource
this.unload();
@@ -321,6 +329,22 @@
this.resourcewidth = 0;
this.resourceheight = 0;
if (event.type == Event.COMPLETE) {
+ var info:LoaderInfo = event.target as LoaderInfo;
+ if (info.content is AVM1Movie) {
+ if ($debug) {
+ Debug.warn("Playback control will not work for the resource. Please update or recompile the resource for Flash 9.", this.resource);
+ }
+ this.loaderMC = null;
+ } else {
+ // store a reference for playback control
+ this.loaderMC = MovieClip(event.target.content);
+
+ this.totalframes = this.loaderMC.totalFrames;
+ this.owner.resourceevent('totalframes', this.totalframes);
+ this.loaderMC.addEventListener(Event.ENTER_FRAME, updateFrames);
+ this.owner.resourceevent('play', null, true);
+ this.playing = this.owner.playing = true;
+ }
try {
var loader:Loader = Loader(event.target.loader);
this.resourcewidth = loader.width;
@@ -360,6 +384,17 @@
}
/**
+ * Handle frame updates for loaded movieclips
+ */
+ private function updateFrames (event:Event) :void {
+ this.frame = this.loaderMC.currentFrame;
+ this.owner.resourceevent('frame', this.frame);
+ if (this.frame == this.totalframes) {
+ this.owner.resourceevent('lastframe', null, true);
+ }
+ }
+
+ /**
* Load/Stream a sound from an URL.
*/
private function loadSound (url:String) :void {
@@ -401,8 +436,7 @@
private function startPlay (frame:Number = 0, isFrame:Boolean = true) :void {
var pos:Number = (isFrame ? (frame / MP3_FPS) : frame) * 1000;
- this.playing = true;
- this.owner.playing = true;
+ this.playing = this.owner.playing = true;
this.soundChannel = this.sound.play(pos, 0, this.soundTransform);
this.addEventListener(Event.ENTER_FRAME, soundFrameHandler);
this.soundChannel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
@@ -415,8 +449,7 @@
private function stopPlay () :Number {
var frame:Number = Math.floor(this.soundChannel.position * 0.001 * MP3_FPS);
- this.playing = false;
- this.owner.playing = false;
+ this.playing = this.owner.playing = false;
this.removeEventListener(Event.ENTER_FRAME, soundFrameHandler);
this.soundChannel.stop();
this.soundChannel = null;
@@ -425,7 +458,7 @@
}
/**
- * Update play status
+ * Update sound play status
*/
private function updatePlay (play:Boolean, framenumber:*, rel:Boolean) :void {
var fr:Number;
@@ -852,14 +885,29 @@
o Plays from the current frame if framenumber is null
*/
public function play (framenumber:* = null, rel:Boolean = false) :void {
- if (! this.isaudio) {
- // TODO [hqm 2008-04] what to do about playing movies?
- stop(framenumber);
- } else {
+ if (this.isaudio) {
// audio-resource is attached
this.updatePlay(true, framenumber, rel);
this.owner.resourceevent('play', null, true);
+ } else if (this.__isinternalresource) {
+ stop(framenumber, rel);
+ } else if (this.loaderMC) {
+ this.owner.resourceevent('play', null, true);
+ this.playing = this.owner.playing = true;
+ if (framenumber == null) {
+ this.loaderMC.play();
+ } else {
+ if (rel) framenumber += this.frame;
+ if (framenumber > this.totalframes) {
+ framenumber = this.totalframes;
+ } else if (framenumber < 1) {
+ framenumber = 1;
+ }
+ this.loaderMC.gotoAndPlay(framenumber);
+ }
+ } else {
+ //Debug.write('unhandled play', framenumber, rel);
}
}
@@ -869,7 +917,13 @@
o Stops at the current frame if framenumber is null
*/
public function stop (fn:* = null, rel:Boolean = false) :void {
- if (! this.isaudio) {
+ if (this.isaudio) {
+ // audio-resource is attached
+ var p:Boolean = this.playing;
+ this.updatePlay(false, fn, rel);
+
+ if (p) this.owner.resourceevent('stop', null, true);
+ } else if (this.__isinternalresource) {
if (this.resource == null || imgLoader) {
return;
}
@@ -924,12 +978,23 @@
//Debug.write('set resource to', asset, oRect);
this.applyStretchResource();
+ } else if (this.loaderMC) {
+ if ( this.playing ) this.owner.resourceevent('stop', null, true);
+ this.playing = this.owner.playing = false;
+ if (fn == null) {
+ this.loaderMC.stop();
+ } else {
+ if (rel) fn += this.frame;
+ if (fn > this.totalframes) {
+ fn = this.totalframes;
+ } else if (fn < 1) {
+ fn = 1;
+ }
+ this.loaderMC.gotoAndStop(fn);
+ }
} else {
- // audio-resource is attached
- var p:Boolean = this.playing;
- this.updatePlay(false, fn, rel);
-
- if (p) this.owner.resourceevent('stop', null, true);
+ // This shouldn't happen - but it does, on roll over
+ //Debug.write('unhandled stop', fn, rel);
}
}
@@ -1151,6 +1216,8 @@
// clear out cached values
this.lastreswidth = this.lastresheight = this.resourcewidth = this.resourceheight = 0;
this.resource = null;
+ this.__isinternalresource = null;
+ this.loaderMC = null;
this.imgLoader = null;
this.resourceObj = null;
}
More information about the Laszlo-checkins
mailing list