Ultrashock Forums > Flash > Flash Newbie
Preloader Problems

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
Preloader Problems
Old 2008-10-28

Hi there!
I'm having massive trouble with preloading an AS3 SWF. I have a seperate Preloader FLA with following script in the first and only frame:

Code:
var PageLoader:Loader = new Loader();
PageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, Progress);
PageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, Complete);
PageLoader.load(new URLRequest('JA.swf'));

function Progress (event:ProgressEvent) {
	/// DO SOMETHING
}

function Complete (event:Event) {
	PageLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, Progress);
	PageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, Complete);
	PageLoader = null;
	
	addChild(event.currentTarget.content);
}

stop();
Now the problem is that:

A -> It never actually loads the swf
B -> it triggers the Complete function over and over ...
postbit arrow 15 comments | 460 views postbit arrow Reply: with Quote   
Registered User
FourTimesDaily is offline
seperator
Posts: 24
2007-12-13
FourTimesDaily lives in Austria
seperator

Ultrashock Member Comments:
nosrevlah's Avatar nosrevlah nosrevlah is offline nosrevlah lives in United States 2008-10-28 #2 Old  
I just copied and pasted your code and created a file called "JA.swf" with a 1 meg .jpg in it and it worked perfectly. Dumb question, what does your "JA.swf" contain???
Reply With Quote  
Isocase's Avatar Isocase Isocase is offline Isocase lives in United States 2008-10-29 #3 Old  
You can try to see if the below works. It's almost the same code except I created a variable for your loader.content.

Code:
var PageLoader:Loader = new Loader();
PageLoader.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS, Progress );
PageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, Complete );
PageLoader.load(new URLRequest('JA.swf'));

function Progress(event:ProgressEvent)
{
	/// DO SOMETHING
}

function Complete(event:Event)
{
	PageLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, Progress);
	PageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, Complete);
	PageLoader = null;
	
	var content:MovieClip = PageLoader.content as MovieClip;
	
	addChild( content );
}
Reply With Quote  
FourTimesDaily FourTimesDaily is offline FourTimesDaily lives in Austria 2008-10-30 #4 Old  
I know! The weird thing is that I used the same Preloader for another Page and it worked just fine! I think that the main problem is, that I load external File's right in the first frame of the JA.swf.

Because as long as i dont load external stuff the Preloader works just. Maybe, the COMLETE Event of the XML I load in the first frame, also Triggers the COMPLETE Event of the Preloader.

To see the Bug, let the Preloader load one of your Pages that load external Content ...
Reply With Quote  
FourTimesDaily FourTimesDaily is offline FourTimesDaily lives in Austria 2008-10-30 #5 Old  
Quote: Originally Posted by nosrevlah View Post
I just copied and pasted your code and created a file called "JA.swf" with a 1 meg .jpg in it and it worked perfectly. Dumb question, what does your "JA.swf" contain???

It's a medium size Flash Page! Nothing special though. Loads an XML right at the beginning! After that i add a view classes to manage the content ... I can send you the code if you want to take a close look at it ....
Reply With Quote  
nosrevlah's Avatar nosrevlah nosrevlah is offline nosrevlah lives in United States 2008-10-30 #6 Old  
Sure, post your code and I will try to help.
Reply With Quote  
FourTimesDaily FourTimesDaily is offline FourTimesDaily lives in Austria 2008-10-30 #7 Old  
Well that is quit a lot to post:

Scene 1/ Frame 1:

Code:
var MasterXML:XMLList;

function Init () {
	var Link:String = 'http://juerke-architekten.kms-team.de/backend/flash-xml.php';
	var XMLRequest:URLRequest = new URLRequest(Link);
	var XMLLoader:URLLoader = new URLLoader();
	
	XMLLoader.addEventListener(Event.COMPLETE, ManageXML);
	XMLLoader.load(XMLRequest);
}

function ManageXML (event:Event) {
	MasterXML = XMLList(event.target.data);;
	nextScene();
}

Init();

stop();
Scene 2/Frame 1:

Code:
///  STAGE SETTINGS  ////

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

/////////////////////////

import External.NavigationControl;
import External.ImageEngine;
import External.ScaleEngine;
import External.ManageContent;

var ImageClass:ImageEngine = new ImageEngine(ImageHolder.Holder);

var ScaleClass:ScaleEngine = new ScaleEngine(stage, this);
ScaleClass.Image = ImageHolder.Holder;

var NavigationClass:NavigationControl = new NavigationControl();
NavigationClass.Reference = Navigation;
NavigationClass.MenuStatus = 'Covered';
NavigationClass.MainTimeline = this;
NavigationClass.Init();

var ContentClass:ManageContent = new ManageContent();
ContentClass.ImageHandler = ImageClass;
ContentClass.ImageHolder = ImageHolder;
ContentClass.MainTimeline = this;
ContentClass.MasterXML = MasterXML;
ContentClass.FunctionClass.MasterXML = MasterXML;
ContentClass.ScaleClass = ScaleClass;
ContentClass.NavigationClass = NavigationClass;
this.addChild(ContentClass);

setTimeout(NavigationClass.Click, 5, 'Default1');



stop();

But the Classes are probably too long to post here - but if you want to i can email you the whole thing ... but that might not be necessary ...

Thanks by the way ....
Reply With Quote  
Anik's Avatar Anik Anik is offline Super Moderator Anik lives in Argentina 27 Creative Assets 2008-11-03 #8 Old  
hey FourTimesDaily i had to delete the other thread you created since you cant create duplicated threads for the same subject, besides you have recived help here, you just have to be pacient, instead of creating another thread for the same subject you can bump this thread, asking for people's help again.
Reply With Quote  
FourTimesDaily FourTimesDaily is offline FourTimesDaily lives in Austria 2008-11-03 #9 Old  
Quote: Originally Posted by Anik View Post
hey FourTimesDaily i had to delete the other thread you created since you cant create duplicated threads for the same subject, besides you have recived help here, you just have to be pacient, instead of creating another thread for the same subject you can bump this thread, asking for people's help again.
Ok - I'm sorry! I didn't know that but it makes sense now that i know ...
You said something about bumping the thread!! How do i do this to get people to get notice of my thread ....

Thanks ...
Reply With Quote  
Nutrox's Avatar Nutrox Nutrox is offline Super Moderator Nutrox lives in United Kingdom 17 Creative Assets 2008-11-03 #10 Old  
One big problem is you are setting the Loader ( PageLoader ) to null before you pull the content from it. Flash should be spitting out an error because of that, if it isn't then TURN ERROR REPORTING BACK ON otherwise you will get stuck like this every time you try doing something with a null object.

If the Loader is only being used to load a single SWF file then you can just add it directly to the display list.

Code:
function complete (event:Event):void {
	pageLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, progress);
	pageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, complete);
	//pageLoader = null;
	
	addChild(pageLoader);
}
FYI: Variable and function names should start with a lowercase character.
Reply With Quote  
FourTimesDaily FourTimesDaily is offline FourTimesDaily lives in Austria 2008-11-03 #11 Old  
Still don't work!

It still triggers the complete function over and over ... plus it never loads the the SWF ...

PS: Is there a certain reason why i should use lowercase characters or is it just more common ?
Reply With Quote  
FourTimesDaily FourTimesDaily is offline FourTimesDaily lives in Austria 2008-11-03 #12 Old  
+ I have the Error Reporting on and it doesn't report anything! What i said in myprevious post is not completley right! It does load the SWF because i can trace the bytes being loaded, it just never adds it to the stage ... !

I hope that info helps
Reply With Quote  
Nutrox's Avatar Nutrox Nutrox is offline Super Moderator Nutrox lives in United Kingdom 17 Creative Assets 2008-11-03 #13 Old  
Are you sure it doesn't add it to the stage? Give this a try...

Code:
function complete (event:Event):void {
	pageLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, progress);
	pageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, complete);
	//pageLoader = null;
	
	addChild(pageLoader);

	trace( contains( pageLoader ) ? "content has been added" : "content has not been added" );
}
If content has been added is traced then the problem is more than likely in the external SWF.

Using lowercase characters at the start of variable and function names is a common coding convention (i.e. it is standard and is expected but not required).

AS3 Coding Conventions
Reply With Quote  
FourTimesDaily FourTimesDaily is offline FourTimesDaily lives in Austria 2008-11-03 #14 Old  
Ok - I checked it and it does add it to the stage! I just never shows the contant! Then i thought the prolem has to be the XML thats loaded right at the beginning of the JA.swf! I thought that it starts loading the XML before it's actually loaded to the stage! But when i stop the XML from being loaded i actually see that content but the whole actionscript (as posted above) is not read ... (you get what i mean?)
Reply With Quote  
FourTimesDaily FourTimesDaily is offline FourTimesDaily lives in Austria 2008-11-12 #15 Old  
So noone got an idea???
Reply With Quote  
Artofacks1 Artofacks1 is offline Artofacks1 lives in United States 2008-11-12 #16 Old  
Last edited by Artofacks1 : 2008-11-12 at 16:16.
Try this class

ActionScript Code:
  1. package
  2. {
  3.  
  4.     import flash.display.MovieClip;
  5.     import flash.display.Loader;
  6.     import flash.net.URLRequest;
  7.    
  8.     import flash.events.ProgressEvent;
  9.     import flash.net.FileReference;
  10.    
  11.  
  12.  
  13.     public class Loaders extends MovieClip
  14.     {
  15.         public var _mainMC:MovieClip;
  16.         //this will be loaded by the json file
  17.         public var _imagePath:String;
  18.         public var loader:Loader;
  19.        
  20.        
  21.        
  22.         public function Loaders(mainMC, imagePath)
  23.         {
  24.            
  25.            
  26.             trace("Loaders ");
  27.             _mainMC = mainMC;
  28.             _imagePath = imagePath;
  29.  
  30.            
  31.             loader = new Loader();
  32.            
  33.             var request:URLRequest = new URLRequest(_imagePath);
  34.             loader.load(request);
  35.            
  36.             loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressBar);
  37.             //loader.contentLoaderInfo.addEventListener(Event.COMPLETE, addChildTo);
  38.         }
  39.        
  40.         public function progressBar(e:ProgressEvent):void
  41.         {
  42.             var percent:Number = Math.floor( (e.bytesLoaded*100) / e.bytesTotal);
  43.             //trace("percent :" + percent);
  44.            
  45.             if ( percent >= 100 )
  46.             {
  47.                 //trace(100 + "%");
  48.                 loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, progressBar);
  49.                 addChildTo();
  50.             }
  51.             //trace("completed loading image " + e.bytesLoaded + " out of " + e.bytesTotal + " bytes");
  52.             //trace("numChildren2" + _mainMC.numChildren);
  53.            
  54.         }
  55.        
  56.         public function addChildTo():void
  57.         {
  58.             if (_mainMC.loader)
  59.             {
  60.                 _mainMC.removeChild(loader);
  61.                 //trace("numChildren" + _mainMC.numChildren);
  62.             }
  63.             _mainMC.addChild(loader);
  64.         }
  65.  
  66.     }
  67. }

you use it like this.

ActionScript Code:
  1. import Loaders;
  2. public var ImageLoaders:Loaders;
  3.  
  4.  ImageLoaders = new Loaders( pass in mc name,  pass in swf name);
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: