all groups > flash actionscript > october 2005 >
You're in the

flash actionscript

group:

CLASS to load clips problem


Re: CLASS to load clips problem *
10/25/2005 3:23:20 PM
flash actionscript:
On Tue, 25 Oct 2005 21:00:36 +0000 (UTC), "pickle jar"
[quoted text, click to view]


Have you tried prefixing bytesLoaded and bytesTotal with the "this" keyword?

this.bytesLoaded
this.bytesTotal

CLASS to load clips problem pickle jar
10/25/2005 9:00:36 PM
Hi all,

I have been following a tutorial in colin moocks as2 book and adapted an
example to load external swf's into movie clip holders. I am trying to get
with the standard oop practice and stick with CLASS building. Here is my
script with 2 issues I seek help with please:

1. onLoadProgress doesn't seem to display the bytes loaded sum I created, even
if I put in a big swf and simulate download on a low bandwidth setting.

2. What is peoples opinion on using this to build a site. I have used movie
clip loader in the past in script in 'say' a index.swf which loads in all the
external swf files to make up the site. Is this script a functional way of
loading a few swf's at the same time to make a site?

cheers in advance,
simon



/* Class to create a container mc which holds a
* target mc to load different content (swfs) into...
*/
class McHolder {
// Movie clip references
private var container_mc:MovieClip;
private var target_mc:MovieClip;
private var contentLoader:MovieClipLoader;

// Movie clip depths
private var containerDepth:Number;
private static var contentDepth:Number = 0;
private static var statusDepth:Number = 1;

// Constructor
public function McHolder (target:MovieClip, depth:Number, x:Number, y:Number,
w:Number, h:Number){
// Assign property values
target_mc = target;
containerDepth = depth;

/* Create the MovieClipLoader instance and store it in
* the new contentLoader property
*/
contentLoader = new MovieClipLoader();

/* Register this McHolder instance to receive events
* from the MovieClipLoader instance
*/
contentLoader.addListener(this);

// Set up visual assets
buildHolder(x, y, w, h);
}

/* Create the clips to hold the content
* this method subcontracts all its work to
* individual clip creation methods...
*/
private function buildHolder(x:Number, y:Number, w:Number, h:Number):Void {
createMainContainer(x, y);
createHolderClip();
}

// Create the container that holds all the assets
private function createMainContainer(x:Number, y:Number):Void {
container_mc = target_mc.createEmptyMovieClip("container_mc" +
containerDepth, containerDepth);
// Position the container clip
container_mc._x = x;
container_mc._y = y;
}
// Creates the clip into which the content is actually loaded
private function createHolderClip():Void{
container_mc.createEmptyMovieClip("content_mc", contentDepth);
}

// Loads the content
public function loadContent (URL:String):Void {
// Use the MovieClipLoader instance to load the image
contentLoader.loadClip(URL, container_mc.content_mc);

// Create a load-status text field to show the user load progress
container_mc.createTextField("loadStatus_txt", statusDepth, 0, 0, 0, 0);
container_mc.loadStatus_txt.background = true;
container_mc.loadStatus_txt.border = true;
container_mc.loadStatus_txt.setNewTextFormat(new TextFormat(
"Arial, Helvetica, _sans",
10, 000000, false,
false, false, null, null,
"right"));
container_mc.loadStatus_txt.autoSize = "left";

// Position the load-status text field
container_mc.loadStatus_txt._y = 3;
container_mc.loadStatus_txt._x = 3;

// Indicate that the content is loading
container_mc.loadStatus_txt.text = "LOADING CONTENT";
}
// MovieClipLoader handler. Triggered by contentLoader when data arrives
public function onLoadProgress (target:MovieClip,
bytesLoaded:Number,
bytesTotal:Number):Void {
// Display load progress in the on-screen text field
// Divide bytesLoaded and bytesTotal by 1024 to get kilobytes
container_mc.loadStatus_txt.text = "LOADING: "
+ Math.floor(bytesLoaded / 1024)
+ "/" + Math.floor(bytesTotal / 1024) + " KB";
}
// MovieClipLoader handler. Triggered by contentLoader when loading is done

public function onLoadInit (target:MovieClip):Void {
// Remove the loading message
container_mc.loadStatus_txt.removeTextField();
}
// MovieClipLoader handler. Triggered by contentLoader when loading fails
public function onLoadError (target:MovieClip, errorCode:String):Void {
if (errorCode == "URLNotFound") {
container_mc.loadStatus_txt.text = "ERROR: File not found.";
} else if (errorCode == "LoadNeverCompleted") {
container_mc.loadStatus_txt.text = "ERROR: Load failed.";
} else {
// Catch-all to handle possible future error codes
container_mc.loadStatus_txt.text = "Load error: " + errorCode;
}
}
/*
* Must be called before the McHolder instance is deleted
* Gives the instance a chance to destroy any resources it has created
*/
public function destroy ():Void {
// Cancel load event notifications
contentLoader.removeListener(this);
// Remove movie clips from Stage (removing container_mc removes subclips)
container_mc.removeMovieClip();
}
}
Re: CLASS to load clips problem LuigiL
10/26/2005 8:02:11 AM
1. The callback functions of the MovieClipLoader class don't work when testing
locally. Load a swf or jpg over http to test (your class works fine, I've
tested it).
2. In my opinion (and let me stress MY) using classes is the best way to go.


Re: CLASS to load clips problem pickle jar
10/27/2005 8:42:00 PM
AddThis Social Bookmark Button