Avatar of cubical38
cubical38
 asked on

AS3: preloader firing 5 times like a loop causing future errors... Please review...

Refer to the code below.  Preloader works, yet fires 5 times before actually loading.  Below is the output when published:

Rotation onProgress is firing
Rotation onProgress second
Rotation onProgress third
Rotation onProgress forth
Rotation onProgress fifth
Rotation onProgress finished
 Rotation onProgress is firing
Rotation onProgress second
Rotation onProgress third
Rotation onProgress forth
Rotation onProgress fifth
Rotation onProgress finished
 Rotation onProgress is firing
Rotation onProgress second
Rotation onProgress third
Rotation onProgress forth
Rotation onProgress fifth
Rotation onProgress finished
 Rotation onProgress is firing
Rotation onProgress second
Rotation onProgress third
Rotation onProgress forth
Rotation onProgress fifth
Rotation onProgress finished
 Rotation onProgress is firing
Rotation onProgress second
Rotation onProgress third
Rotation onProgress forth
Rotation onProgress fifth
Rotation onProgress finished
Rotation it must have loaded

One other thing to consider is that I am using a ControlVR component within this piece but even when removed I get the same output.  5 times over...

Any thoughts?

Thanks again...
import flash.net.URLLoader;
import flash.net.URLRequest;
 
stop();
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
this.loaderInfo.addEventListener(Event.COMPLETE, onComplete);
 
function onProgress(e:ProgressEvent):void {trace(" 360 onProgress is firing");
	var loaded:Number = e.target.bytesLoaded;trace("360 onProgress second");
	var total:Number = e.target.bytesTotal;trace("360 onProgress third");
	var pct:Number = loaded/total;trace("360 onProgress forth");
	pre_mc.loader_mc.scaleX = pct;trace("360 onProgress fifth");
	pre_mc.loaded_txt.text = "Loading... " + (Math.round(pct * 100)) + "%";trace("360 onProgress finished");
}
 
 
function onComplete(e:Event):void {
	TweenLite.to(pre_mc, .5, {y:"-50",alpha: 0, ease:Back.easeInOut, onComplete:gotoAndPlay, onCompleteParams:[2]});
	trace("360 it must have loaded");
}

Open in new window

Web Development SoftwareAdobe Flash

Avatar of undefined
Last Comment
cubical38

8/22/2022 - Mon
blue-genie

what's being output is correct. you must remember that the onProgress method will keep triggering until it's finished, hence those traces will be repeated until the loading process is complete.
cubical38

ASKER
That what I was thinking, but I am getting an error.  Below is the code that I have to load in 3 different swfs, yet on the third click I receive the always unpopular TypeError: Error #1009: Cannot access a property or method of a null object reference at Hilti_fla::MainTimeline/onProgress()

Each swf has a preloader, but it is the same code as above for each...

Maybe you can see something I am overlooking...

Thanks...
var myTimer:Timer = new Timer(2000, 1);
myTimer.addEventListener(TimerEvent.TIMER, GetOut);
myTimer.start();
function GetOut(event:TimerEvent):void {
	TweenLite.to(rotate_mc, .9, {alpha: 0, ease:Back.easeInOut});
	trace("uh oh! the timer has begun");
 
	var buttons:Array =[moreInfo_btn,rotate_btn,magnify_btn];
 
	var links:Array =["HiltiCallouts.swf","Hilti-Rotation.swf","Hilti-Magnify.swf"];
 
	var hotspotY:Array =[20,40,0];
 
	var link = String(links[0]);
	var currentBtn:MovieClip;
	var previousBtn = MovieClip(buttons[0]);
	var hotspot:Loader = new Loader();
	addChild(hotspot);
 
	function initSite():void {
		for (var i:Number = 0; i < buttons.length; i++) {
			buttons[i].id = i;
			buttons[i].alpha = .2;
			buttons[i].buttonMode = true;
			buttons[i].mouseChildren = false;
			buttons[i].addEventListener(MouseEvent.MOUSE_OVER, btnOver);
		}
		previousBtn.mouseEnabled = false;
		previousBtn.alpha = 1;
		hotspot.y = hotspotY[0];
		hotspot.load(new URLRequest(link));trace("link");
		trace(link);
	}
	initSite();
 
	function btnOver(e:MouseEvent):void {
		e.target.alpha = 1;
		e.target.addEventListener(MouseEvent.MOUSE_OUT, btnOut);
		e.target.addEventListener(MouseEvent.CLICK, btnClick);
	}
 
	function btnOut(e:MouseEvent):void {
		e.target.alpha = .2;
	}
 
	function btnClick(e:MouseEvent):void {
		link = String(links[ e.target.id ]);
		hotspot.y = Number(hotspotY[ e.target.id ]);
		trace(link, hotspot.y);
		e.target.removeEventListener(MouseEvent.MOUSE_OUT, btnOut);
		e.target.removeEventListener(MouseEvent.CLICK, btnClick);
		currentBtn = MovieClip(buttons[ e.target.id ]);
		currentBtn.alpha = 1;
		previousBtn.alpha = .2;
		currentBtn.mouseEnabled = false;
		previousBtn.mouseEnabled = true;
		previousBtn = currentBtn;
		hotspot.load(new URLRequest(String(link)));
	}
 
}

Open in new window

blue-genie

i'm confused. i'm not following the process here.

you have 3 swf files.

where is the code you posted (the progress stuff and the other stuff).
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
cubical38

ASKER
I know its kind of tricky to explain as everything is working fine I just keep getting this error in my output window:
#1009: Cannot access a property or method of a null object reference at Hilti_fla::MainTimeline/onProgress()

the code at the top of the page is my preloader, which is on frame 1...

the next snippet of code is my array for loading in the 3 swfs, which also has some button functionality, which also all works.

once i test the movie everything loads fine, i click the first button and load in another swf, which works fine.

Now when I try and click on another button, everything fires as it should yet within my out put I receive the above mentioned error...

I have traced every function in the piece but all are firing at the correct time and local...

This may just be a bug with the classes I am using...  I wish AS3 had better debugging capabilities...

If this still makes little sense as it does to me, no worries, the piece works, so...  I just hate output errors especially this one...

Thanks for taking a look...
blue-genie

okay its a tad difficult for me to try stuff without being able to replicate it. but why are you removing your mouselistener everytime you call btnClick?

that might be a problem.
a cheat i implement - whoever is throwing the null reference error i always just put in a check that if its not null then do whatever - that prevents the runtime error message.
cubical38

ASKER
Do you mean trace the error, when you say "check"?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
blue-genie

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
cubical38

ASKER
Okay I was able to find the issue, it was taking the preloader off of the stage in the 2nd frame.  Flash is so fickle...  Thanks again...