The Ultrashock Ultra Bundle
  • Home
  • Community
  • Forum
  • Flash
  • Flash Newbie
  • Thread
  •  
  • Previous topic
  • Next topic
Sign up to post

Flash
 Flash Newbie

  • FourTimesDaily Author 
    • 548 
    • 0 
    • 15 
    Preloader Problems
    Artofacks1

    Last reply Nov 12 2008, 06:58 PM

    by Artofacks1

    Posted: Oct 28 2008, 08:03 PM

    by FourTimesDaily

     

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 ...

  15 REPLIES
 
nosrevlah
1  
nosrevlah

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???

  • 28 October 2008 10:21 PM
  •  
Isocase
2  
Isocase

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
  •  
FourTimesDaily Author 
3  
FourTimesDaily

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
  •  
FourTimesDaily Author 
4  
FourTimesDaily [QUOTE=nosrevlah;761995]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 ....

  • 30 October 2008 02:03 PM
  •  
nosrevlah
5  
nosrevlah

Sure, post your code and I will try to help.

  • 30 October 2008 02:12 PM
  •  
FourTimesDaily Author 
6  
FourTimesDaily

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 .... smilie

  • 30 October 2008 02:46 PM
  •  
Anik
7  
Anik

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
  •  
FourTimesDaily Author 
8  
FourTimesDaily [QUOTE=Anik;762162]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 ... smilie
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
  •  
Nutrox
9  
Nutrox

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
  •  
FourTimesDaily Author 
10  
FourTimesDaily

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
  •  
FourTimesDaily Author 
11  
FourTimesDaily

+ 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
  •  
Nutrox
12  
Nutrox

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).

AS3 Coding Conventions

  • 03 November 2008 12:54 PM
  •  
FourTimesDaily Author 
13  
FourTimesDaily

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
  •  
FourTimesDaily Author 
14  
FourTimesDaily

So noone got an idea???

  • 12 November 2008 09:03 AM
  •  
Artofacks1
15  
Artofacks1

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.
 
Topic actions
  •  Share on Facebook
  •  Share on Twitter
Topic Categories
  •  Show All Topics
  •  Development
    •  Server Side
    •  Client Side
  •  Creative Software
    •  Web
    •  Video
    •  3D
    •  Illustrator
    •  Photoshop Battles
    •  Photoshop
  •  Design
    •  Typography
    •  Resources & Insight
    •  Checkpoint
  •  Career
    •  Copyright Matters
    •  Advice & issues
    •  Job Seekers
    •  Job Offers
  •  Flash
    •  UltraMath
    •  OOP
    •  Third Party Tools
    •  Open Source alternatives
    •  Data Communication
    •  Components
    •  Flex
    •  AIR
    •  Flash Lite
    •  Flash Professional
    •  Flash Newbie
    •  ActionScript
    •  XML
  •  Lounge
    •  Polls
    •  Random Chat
    •  Showcase And Critique
    •  BombShock Award Nominations
  •  Community Essentials
    •  BombShock Award Winners
    •  Tutorials
    •  Interviews
    •  News
    •  Bitmap tutorials
Popular Topics
  • Sort by: 
  • Activity
  • Views
  • Comments
  • Likes
Advertise with us
  • Your advertisement here!
  • loading
Ultrashock
  • Creative Assets
  • Community
  • Blog
  1. Home
  2. Forum
+/-
Creative Assets
  • Categories
  • Contributors
  • How to buy
Make Money
  • Commission Rates
  • Referral Program
  • Contributor Program
Community
  • Activity Feed
  • Forum
  • Profiles
About
  • Quick Tour
  • Our History
  • Banners & Logos
Support
  • Contact Ultrashock
  • Advertise with us
  • Legal Information
  •  Keep up to date
  • Flash 779  Flash
  • Audio 6,481  Audio
  • Vector 2,130  Vectors
  • Image 12,338  Images
  • Creative Assets 21,728  Assets
  • Profiles 282,751  Members
  • Topics 93,776  Topics
  • Blog 4  Blog
  • Facebook 1,679  Facebook
  • Twitter 1,163  Twitter
  • Join our FREE monthly newsletter!
  • Archive
  • Invalid email address. Please try again.
Subscribe
  • ©2012 Ultrashock LLC - All rights reserved
  • Terms of Use
  • Privacy Policy
  • Switch to dark theme
  • RSS Feeds
  • Top

©2012 Ultrashock LLC - All rights reserved

Printed on Sat, February 11, 2012 - 20:13:18