Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

 
 
Thread Tools Rating: Thread Rating: 8 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
Old 08-29-2007, 08:40 PM   #1
charlieFlash
another concerned citizen
 
charlieFlash's Avatar
 
Join Date: Feb 2002
Location: Fayetteville, NY
Posts: 149
Send a message via AIM to charlieFlash
Default Loading a swf created using document class gives error #1009

Hey there,
Well the shiny new app is now 830K and needs to be preloaded. Simple eh? I've got a preloader that works nicely but I've been trying all day to find a reasonable way to load a swf that was compiled as a document class. My solution was to make a bare bones swf that would preload my main app swf:

Code:
/*******************************************************
*
* Document level class for app
*
*******************************************************/
package {
	import flash.display.Stage;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.display.MovieClip;
	//import Preloader;
	import ProgressDisplay;
	//
	public class App extends TopLevel {
		
		// constructor function
		public function App () {
			stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
			// load test file
			//var p:Preloader = new Preloader("test.jpg", this);
			var p:ProgressDisplay = new ProgressDisplay("FlexiportApp.swf", this, stage.stageWidth/2, stage.stageHeight/2);
			addChild(p);
			//preload ("test.jpg", this);
		}
		
	}

}
Code:
/*******************************************************
*
* Document level class for app
*
*******************************************************/
package {
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.text.TextField;
	import Preloader;
	//
	public class ProgressDisplay extends Preloader {
		//
		private var barWidth:Number;
		// constructor function calls the super
		public function ProgressDisplay (_file:String, _target:DisplayObjectContainer, _x:Number, _y:Number) {
			super(_file, _target, _x, _y);
			barWidth = _progressBar.width;
		}
		// 
		public override function displayProgress (percent:Number):void {
			/*
			* Dispatched from loadProgress.
			* This function may be overridden for use with specific preloader instances.
			*/
			// decide how to interpret the display of the preloader here!
			var msg:String = percent+"%";
			_progress_txt.text = msg;
			// set the width of the progress bar
			_progressBar.width = barWidth * (percent/100);
			//trace (msg);
		}
	}

}
If I load a swf that has no document class I'm all good. If I try to load a swf that had a document class I get this error:
Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at FlexiportApp$iinit()
The app swf runs fine on its own. The swf does actually preload however, it just doesn't run. Any thoughts? I'll post my preloader class up here in case it helps:
Code:
/*******************************************************
*
* Preloader Class
*
*******************************************************/
package {
	import flash.display.MovieClip;
	import flash.display.DisplayObjectContainer;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	import caurina.transitions.Tweener;
	import flash.system.ApplicationDomain;
    import flash.system.LoaderContext;
	//
	public class Preloader extends MovieClip {
		// set up a loader object
		private static  var loader:Loader = new Loader();
		private static var target:DisplayObjectContainer;
		private static var file:String;
		private static var TRANS_TYPE:String = "fadeIn";
		private static var TRANS_TIME:Number = 0.75;
		private static var TRANS_DELAY:Number = 0;
		private static var TRANS_EASE:String = "easeOutCirc";
		// constructor function
		public function Preloader (_file:String, _target:DisplayObjectContainer, _x:Number, _y:Number) {
			// add the listeners
			loader.contentLoaderInfo.addEventListener (Event.OPEN, loadOpen);
			loader.contentLoaderInfo.addEventListener (ProgressEvent.PROGRESS, loadProgress);
			loader.contentLoaderInfo.addEventListener (Event.INIT, loadInit);
			loader.contentLoaderInfo.addEventListener (Event.COMPLETE, loadComplete);
			loader.contentLoaderInfo.addEventListener (IOErrorEvent.IO_ERROR, ioError);
			//
			file = _file;
			target = _target;
			//
			x = _x;
			y = _y;
			//x = target.stage.stageWidth/2;
			//y = target.stage.stageHeight/2;
			// load test file
			preload ();
		}
		//
		private function loadOpen (event:Event):void {
			/*
			* Dispatched when a load operation starts.
			*/
			trace ("Open");
		}
		//
		private function loadProgress (event:ProgressEvent):void {
			/*
			* Dispatched when data is received as the download operation progresses.
			*/
			var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
			percentLoaded = Math.round(percentLoaded * 100);
			// display preloader here!
			displayProgress (percentLoaded);
		}
		//
		private function loadInit (event:Event):void {
			/*
			* All properties and methods associated with the loaded object and those associated with the LoaderInfo object are accessible.
			* The constructors for all child objects have completed.
			*/
			trace ("Init");
		}
		//
		private function loadComplete (event:Event):void {
			/*
			* Dispatched when data has loaded successfully. The complete event is always dispatched after the init event.
			* Content is is ready to display.
			*/
			trace ("Complete");
			target.addChild (loader);
			loadTransition (loader, TRANS_TYPE, transComplete);
			
			// transition out the preloader
			//transOut ();
			loadTransition (this, "fadeOut", undefined);
		}
		//
		private function ioError (event:IOErrorEvent):void {
			/*
			* Dispatched when an input or output error occurs that causes a load operation to fail.
			*/
			trace (event);
		}
		//
		private function preload ():void {
			/*
			*	Sends the request to start the loading process 
			*	Adds the loaded content the targeted container
			*/
			//-----------------------------------------------
			// child SWF uses parent domain definitions
			// if defined there, otherwise its own
			var childDefinitions:LoaderContext = new LoaderContext();
			childDefinitions.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
			
			// child SWF adds its unique definitions to
			// parent SWF; both SWFs share the same domain
			// child SWFs definitions do not overwrite parents
			var addedDefinitions:LoaderContext = new LoaderContext();
			addedDefinitions.applicationDomain = ApplicationDomain.currentDomain;
			
			// child SWF domain is completely separate and
			// each SWF uses its own definitions
			var separateDefinitions:LoaderContext = new LoaderContext();
			separateDefinitions.applicationDomain = new ApplicationDomain();

			//-----------------------------------------------
			//transIn ();
			loadTransition (this, "fadeIn", undefined);
			var request:URLRequest = new URLRequest(file);
			try {
				// set loader context in load()
				//loader.load (request, addedDefinitions);
				loader.load (request);
			} catch (error:SecurityError) {
				trace (error);
			}
		}
		// 
		public function displayProgress (percent:Number):void {
			/*
			* Dispatched from loadProgress.
			* This function may be overridden for use with specific progress display instances.
			*/
			// decide how to interpret the display of the preloader here!
			trace ("Loading Progress: "+percent+"%");
		}
		
		//
		private function loadTransition (mc:Object, type:String, completeFunc:Function):void {
			/*
			* performs transition on passed in object.
			*/
			switch (type) {
				case "none" :
					break;
				case "fadeIn" :
					// fade in the loaded content
					mc.alpha = 0;
					Tweener.addTween (mc, {alpha:1, time:TRANS_TIME, delay:TRANS_DELAY, transition:TRANS_EASE, onComplete:completeFunc} );
					break;
				case "fadeOut" :
					// fade in the loaded content
					Tweener.addTween (mc, {alpha:0, time:TRANS_TIME, delay:TRANS_DELAY, transition:TRANS_EASE, onComplete:completeFunc} );
					break;
				case "slideInRight" :
					// fade in the loaded content
					//mc.x = target.stage.stageWidth;
					mc.x = mc.width;
					Tweener.addTween (mc, {x:0, time:TRANS_TIME, delay:TRANS_DELAY, transition:TRANS_EASE, onComplete:completeFunc} );
					break;
				case "slideInLeft" :
					// fade in the loaded content
					mc.x = -mc.width;
					Tweener.addTween (mc, {x:0, time:TRANS_TIME, delay:TRANS_DELAY, transition:TRANS_EASE, onComplete:completeFunc} );
					break;
				case "slideInTop" :
					// fade in the loaded content
					mc.y = -mc.height;
					Tweener.addTween (mc, {y:0, time:TRANS_TIME, delay:TRANS_DELAY, transition:TRANS_EASE, onComplete:completeFunc} );
					break;
				case "slideInBottom" :
					// fade in the loaded content
					mc.y = mc.height;
					Tweener.addTween (mc, {y:0, time:TRANS_TIME, delay:TRANS_DELAY, transition:TRANS_EASE, onComplete:completeFunc} );
					break;
				default:
					break;
			}
		}
		//
		private function transComplete ():void {
			/*
			* This function may be overridden for use with specific progress display instances.
			*/
			trace ("transComplete! ");
			visible = false;
			delete this;
		}
		
		
	}

}
__________________
{ charlie : flashDeveloper }

// concept. code. test. debug. test again.
if (success) {
beer();
} else {
coffee();
}
charlieFlash is offline   Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Static members in another document class lucas_wallsi ActionScript 3.0 0 06-26-2007 12:38 PM
Loading external swf, then loading data... mike248 Other Flash General Questions 1 05-27-2007 02:11 AM
Loading on-top of existing swf (then unloading previous swf)?? papalazarou78 ActionScript 2.0 6 05-10-2007 11:25 PM
Loading external swf not working AFFIX HTML and JavaScript 1 04-16-2007 03:20 PM
Database simulated with arrays on a cd-rom lecasn5 Components 61 09-07-2004 11:40 AM


All times are GMT. The time now is 05:48 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.