PDA

View Full Version : At Wits end with PreLoading Issue


apexx
12-07-2010, 04:39 PM
Long Time Listener, 2nd time caller...

thanks in advance for any thought or help on this topic....

long story short, im trying to preload in AS3...

i have already followed a few tutorials on the topic:

when implementing the much simpler first technique, i receive no errors or outputs...

whenever i publish, all i get is a white screen, the profiler shows that the .swf is loading into the preloader, but nothing is showing (not even the pre-loader)

once the loaded swf is done loading, nothing shows up, even after being added to the display list…

in theory, this code should get the job done in a bare minimum fashion:

"percent" is the instance name of a blank dynamic textbox on the stage...


var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(ProgressEvent .PROGRESS, loop);
l.contentLoaderInfo.addEventListener(Event.COMPLET E, done);
l.load(new URLRequest("content.swf"));

function loop(e:ProgressEvent):void
{
var perc:Number = e.bytesLoaded / e.bytesTotal;
percent.text = Math.ceil(perc*100).toString();
}

function done(e:Event):void
{
removeChild(percent);
percent = null;
addChild(l);
}




secondly, i tried another tutorial for a more dynamic look for the preloader...

this tutorial for external preloading worked great as long as you were trying to load anything but a .swf, which is exactly what i need to load..


the AS3 for this tutorial is here:

//Impor TweenMax
import com.greensock.*;

//We will add all the preloader circles to a holder movie clip
var holder:MovieClip = new MovieClip();

//This array will contain all the preloader circles
var circles:Array = new Array();

//This for loop creates and positions 5 preloader circles horizontally
for (var i:uint=0; i < 5; i++) {

//Create a new preloader circle
var circle:PreloaderCircle = new PreloaderCircle();

//Set the x position for the circle
circle.x = i * 20;

//Set the "tweened" property to false since we haven't tweened the circle yet
circle.tweened = false;

//Add the circle to the circles array
circles.push(circle);

//Add the circle to the holder
holder.addChild(circle);
}

//Add the holder to the stage
addChild(holder);

//Position the holder to the center of the stage
var holderWidth:Number = holder.width;
var holderHeight:Number = holder.height;
holder.x = stage.stageWidth / 2 - holderWidth / 2;
holder.y = stage.stageHeight / 2 - holderHeight / 2;

//Create a loader which loads the image
var loader = new Loader();

//Let's load the image.
//You can use your own URL here...
loader.load(new URLRequest("mainflash.swf"));

//Listen for the loading progress
loader.contentLoaderInfo.addEventListener(Progress Event.PROGRESS, progressHandler);

//This function is called as the loading progresses
function progressHandler(e:ProgressEvent):void {

//Check how much has been loaded (in percentages)
var loadedPercentage:Number = (e.bytesLoaded / e.bytesTotal) * 100;

//If over 20% is loaded, tween the first circle if it hasn't been tweened yet.
if (loadedPercentage > 20 && ! circles[0].tweened) {

//Tween the circle
TweenMax.to(circles[0], 1, {tint:0xff8800, glowFilter:{color:0xff8800, alpha:1, blurX:10, blurY:10}});
}

//If over 40% is loaded, tween the second circle if it hasn't been tweened yet.
if (loadedPercentage > 40 && ! circles[1].tweened) {

//Tween the circle
TweenMax.to(circles[1], 1, {tint:0xff8800, glowFilter:{color:0xff8800, alpha:1, blurX:10, blurY:10}});
}

//If over 60% is loaded, tween the third circle if it hasn't been tweened yet.
if (loadedPercentage > 60 && ! circles[2].tweened) {

//Tween the circle
TweenMax.to(circles[2], 1, {tint:0xff8800, glowFilter:{color:0xff8800, alpha:1, blurX:10, blurY:10}});
}

//If over 80% is loaded, tween the fourth circle if it hasn't been tweened yet.
if (loadedPercentage > 80 && ! circles[3].tweened) {

//Tween the circle
TweenMax.to(circles[3], 1, {tint:0xff8800, glowFilter:{color:0xff8800, alpha:1, blurX:10, blurY:10}});
}

//If 100% is loaded, tween the fifth circle if it hasnn't been tweened yet.
if (loadedPercentage == 100 && ! circles[4].tweened) {

//Tween the circle and call the function circlesTweened() when the tween is complete (this is the last circle).
TweenMax.to(circles[4], 1, {tint:0xff8800, glowFilter:{color:0xff8800, alpha:1, blurX:10, blurY:10}, onComplete: circlesTweened});
}
}

//This function is called when the cirlces have been tweened (the image is loaded)
function circlesTweened():void {

//Loop through the circles
for (var i = 0; i < circles.length; i++) {

//Tween the circles to the left side of the stage.
//Call the function circleLeft() when the tween is finished
TweenMax.to(circles[i], 0.5, {delay: i * 0.1, x: -200, alpha: 0, onComplete: circleLeft, onCompleteParams: [circles[i]]});
}
}

//This function is called when a circle is animated to the left side.
function circleLeft(circle:PreloaderCircle):void {

//Remove the circle from the stage
holder.removeChild(circle);

//Check if the circle is the last one (most right)
if (circle == circles[4]) {

//Remove the holder from the stage
removeChild(holder);

//Get the bitmap from the loader
var bm:Bitmap = (Bitmap)(loader.content);

//Add the bitmap to a movie clip holder
var bmHolder:MovieClip = new MovieClip();
bmHolder.addChild(bm);

//Add the bitmap holder to the stage
addChild(bmHolder);

//Animate the bitmap holder
TweenMax.from(bmHolder, 1, {alpha: 0});
}
}


when i changed the URL to "mainflash.swf", i recieved the following error in the output:


Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
TypeError: Error #1034: Type Coercion failed: cannot convert mainflash_fla::MainTimeline@620510b1 to flash.display.Bitmap.


Im at wits end with this issue, nothing seems to be working for a project i would have had done if i did it in AS2, but would like to continue making the jump to AS3...

Thanks for all comments

apexx
12-07-2010, 06:48 PM
this is absolutely infuriating, ive triple checked my code and seen numorous tutorials throughout the day and still cannot figure out why it will load but not display anything (preloader, or loaded swf)

wallacemarino
12-10-2010, 07:13 AM
After playing around with your first example for a few minutes it seems the problem lies in this line when converting the number data to a string;

percent.text = Math.ceil(perc*100).toString();

Instead of using a text box which requires a string I added a rectangular movie clip and had the perc variable affect it's scale on the x axis (a traditional loading bar), this requires a number not a string to operate and it worked fine. Here is my version;

var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(ProgressEvent .PROGRESS, loop);
l.contentLoaderInfo.addEventListener(Event.COMPLET E, done);
l.load(new URLRequest("IScom.swf"));

function loop(e:ProgressEvent):void
{
var perc:Number = e.bytesLoaded / e.bytesTotal;
Img_mc.scaleX = perc

}

function done(e:Event):void
{
addChild(l);
}

Img_mc is simply a coloured rectangle converted to a movie clip.

Hope this helps.