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:
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 ...
You can try to see if the below works. It’s almost the same code except I created a variable for your loader.content.
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 );
}
- 29 October 2008 12:17 PM
-
Author
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 ...
- 30 October 2008 01:58 PM
-
Author
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 ....
- 30 October 2008 02:03 PM
-
Author
Well that is quit a lot to post:
Scene 1/ Frame 1:
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:
/// 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 ....
- 30 October 2008 02:46 PM
-
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.
- 03 November 2008 10:49 AM
-
Author
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 ...
- 03 November 2008 10:56 AM
-
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.
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.
- 03 November 2008 12:05 PM
-
Author
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 ?
- 03 November 2008 12:24 PM
-
Author
+ 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
- 03 November 2008 12:27 PM
-
Are you sure it doesn’t add it to the stage? Give this a try…
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).
- 03 November 2008 12:54 PM
-
Author
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?)
- 03 November 2008 01:28 PM
-
Try this class
[as]
package
{
import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.ProgressEvent;
import flash.net.FileReference;
public class Loaders extends MovieClip
{
public var _mainMC:MovieClip;
//this will be loaded by the json file
public var _imagePath:String;
public var loader:Loader;
public function Loaders(mainMC, imagePath)
{
trace(“Loaders “);
_mainMC = mainMC;
_imagePath = imagePath;
loader = new Loader();
var request:URLRequest = new URLRequest(_imagePath);
loader.load(request);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressBar);
//loader.contentLoaderInfo.addEventListener(Event.COMPLETE, addChildTo);
}
public function progressBar(e:ProgressEvent):void
{
var percent:Number = Math.floor( (e.bytesLoaded*100) / e.bytesTotal);
//trace(“percent :” + percent);
if ( percent >= 100 )
{
//trace(100 + “%”);
loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, progressBar);
addChildTo();
}
//trace(“completed loading image ” + e.bytesLoaded + ” out of ” + e.bytesTotal + ” bytes”);
//trace(“numChildren2” + _mainMC.numChildren);
}
public function addChildTo():void
{
if (_mainMC.loader)
{
_mainMC.removeChild(loader);
//trace(“numChildren” + _mainMC.numChildren);
}
_mainMC.addChild(loader);
}
}
}[/as]
you use it like this.
[as]
import Loaders;
public var ImageLoaders:Loaders;
ImageLoaders = new Loaders( pass in mc name, pass in swf name);[/as]
- 12 November 2008 06:58 PM
-
- Log in or join for free to make a comment.


