Jump to content


Photo

AS3 External Preloader


  • Please log in to reply
1 reply to this topic

#1 BlazeForc3

BlazeForc3

    Young Padawan

  • Members
  • Pip
  • 62 posts
  • Location:Australia

Posted 06 June 2008 - 05:16 AM

Ok so I have two swf files, content.swf and main.swf (preloader).

I have setup main.swf with the document class below:

package classes
{
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.display.Loader;
	import flash.net.URLRequest;
	import flash.display.MovieClip;
	public class LoaderClass extends MovieClip
	{
		public function LoaderClass():void
		{
			var req:URLRequest = new URLRequest("content.swf");
			var loader:Loader = new Loader();
			
			loader.load(req);
			addChild(loader);
			
			loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
		}
		
		public function loadProgress(e:ProgressEvent):void
		{
			var percent:Number = e.bytesLoaded/e.bytesTotal;
			percent = percent * 100;
			MC_Loader.loader_txt.text = percent;
		}

		public function loadComplete(e:Event):void
		{
			trace("Complete!");
		}
	}
}

In the content.swf I have just chucked a hi res image just to try out the loader. The problem is it works fine when I test it in flash (Control -> Test Movie) but when I upload it to my host it doesn't work properly, loader_txt goes from 0 to 100 instantly yet the image has clearly not finished loading???

bytesLoaded and bytesTotal appear to report incorrectly inside the browser but I don't know why or of an alternative method?

Edit: It seems like bytesLoaded and bytesTotal are always the same, not sure why that is?

Edited by BlazeForc3, 06 June 2008 - 09:37 AM.


#2 curthard89

curthard89

    Young Padawan

  • Members
  • Pip
  • 226 posts

Posted 10 July 2008 - 05:30 PM

when loading from external resources in flash, it has a security issue, if the image is not on the server the flash file is on then the image wont get loaded because of the flash security issue, there is no way around this. You will have to use php or something to grab the image so it looks like its on your server.

I have almost finnished making this:

http://www.geekygoodness.com/imflow/

and i came across this problem also, i call a php script i made to grab the image.

It sucks, i know...

Also you dont want :void

on the public function LoaderClass

as its the constructor and you want to return itself.

Edited by curthard89, 10 July 2008 - 05:32 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users