Home Tutorials Forums Articles Blogs Movies Library Employment Press

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

Reply
 
Thread Tools Rate Thread Display Modes
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
Old 08-30-2007, 05:36 PM   #2
charlieFlash
another concerned citizen
 
charlieFlash's Avatar
 
Join Date: Feb 2002
Location: Fayetteville, NY
Posts: 149
Send a message via AIM to charlieFlash
Default

OK. Solved the issue. Error was due to this code in the loaded swf:

Code:
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.displayState = StageDisplayState.FULL_SCREEN;
The error was not very specific, oh well. Lesson learned I think.
__________________
{ charlie : flashDeveloper }

// concept. code. test. debug. test again.
if (success) {
beer();
} else {
coffee();
}
charlieFlash is offline   Reply With Quote
Old 07-07-2010, 10:35 PM   #3
stalkio
Registered User
 
Join Date: May 2010
Posts: 11
Default same issue

Hey charlieFlash,

I know you sorted this a while ago now but i'm having exactly the same issue! You said in your final post that it was the code:

Code:
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.displayState = StageDisplayState.FULL_SCREEN;
What did you do to sort this? I commented out this in my code and no joy, what else did you do? Or what else could I try, If you need my code just say the word.

Stalks
stalkio is offline   Reply With Quote
Old 07-07-2010, 11:41 PM   #4
ASWC
Super Moderator
 
ASWC's Avatar
 
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528
Default

If you create a swf meant to be loaded by another swf then you cannot directly reference the stage since the stage will not be available when the loaded swf will try to access it (it will only after the loaded swf is added to the display list). So any direct reference to stage will produce this error in the loaded swf. You solve this by using the ADDED_TO_STAGE event.
__________________
aswebcreations
Super Duper!
ASWC is offline   Reply With Quote
Old 07-08-2010, 02:01 AM   #5
stalkio
Registered User
 
Join Date: May 2010
Posts: 11
Default

Have read some tuts on the ADDED_TO_STAGE event and kind of understand it, however it's not really a beginner topic.

tried to implement it in a couple of ways and still drawing a blank please find the code below. hope you have some ideas. As i'm out of my depth.
Code:
//Preloader from Lee Brimslow I think from gotoandlearn
var l:Loader = new Loader();

l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
l.load(new URLRequest("website.swf"));


function loop(e:ProgressEvent):void
{
	var perc:Number = e.bytesLoaded / e.bytesTotal;
	trace(e.bytesTotal);
	trace(e.bytesLoaded);
	percent.text = Math.ceil(perc*100).toString();
}
function done(e:Event):void
{
	removeChildAt(0);
	percent = null;
	addChild(l);
}
This then loads the fla website

Code:
//The documnet class is Website.as
	
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import flash.events.ContextMenuEvent;
import flash.net.navigateToURL;
import flash.net.URLRequest;

//Make the menubar from Website.as
makeMenu();

//Add the menubar event listners
home.addEventListener(MouseEvent.CLICK, homeClicked);
products.addEventListener(MouseEvent.CLICK, productsClicked);
support.addEventListener(MouseEvent.CLICK, supportClicked);
contact.addEventListener(MouseEvent.CLICK, contactClicked);

function homeClicked(event:MouseEvent):void {
	bg.gotoAndStop(1);
	middle.gotoAndStop(1);
}
function productsClicked(event:MouseEvent):void {
	bg.gotoAndStop(2);
	middle.gotoAndStop(2);
}
function supportClicked(event:MouseEvent):void {
	bg.gotoAndStop(3);
}
function contactClicked(event:MouseEvent):void {
	bg.gotoAndStop(4);
}

//RightClick Menu
var myMenu:ContextMenu = new ContextMenu();
myMenu.hideBuiltInItems();

var menuItem1:ContextMenuItem = new ContextMenuItem("Thanks for visiting the IT Bureau website");
var menuItem2:ContextMenuItem = new ContextMenuItem("Home");
var menuItem3:ContextMenuItem = new ContextMenuItem("Products");
var menuItem4:ContextMenuItem = new ContextMenuItem("Support");
var menuItem5:ContextMenuItem = new ContextMenuItem("Contact Us");
var menuItem6:ContextMenuItem = new ContextMenuItem("----------");
var menuItem7:ContextMenuItem = new ContextMenuItem("Go to the Laminex website");
menuItem2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, homeContext);
menuItem3.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, productsContext);
menuItem4.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, supportContext);
menuItem5.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, contactContext);
menuItem7.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, laminexContext);
myMenu.customItems.push(menuItem1);
myMenu.customItems.push(menuItem2);
myMenu.customItems.push(menuItem3);
myMenu.customItems.push(menuItem4);
myMenu.customItems.push(menuItem5);
myMenu.customItems.push(menuItem6);
myMenu.customItems.push(menuItem7);
this.contextMenu = myMenu;

function homeContext(e:ContextMenuEvent):void {
	bg.gotoAndStop(1);
}
function productsContext(e:ContextMenuEvent):void {
	bg.gotoAndStop(2);
}
function supportContext(e:ContextMenuEvent):void {
	bg.gotoAndStop(3);
}
function contactContext(e:ContextMenuEvent):void {
	bg.gotoAndStop(4);
}
function laminexContext(e:ContextMenuEvent):void {
	var url:String = "www";
	var request:URLRequest = new URLRequest(url);
	navigateToURL(request, '_blank')
}
And finally the documnet class Website.as

Code:
package {

	import flash.display.*;
	import flash.events.*;
	import FluidLayout.*;
	import fl.transitions.easing.*;
	import fl.transitions.*;

	public class Website extends MovieClip {

		//Main layout Vars
		public var bg = new Background();
		public var title = new Title();
		public var footer = new Footer();
		public var middle = new Middle();

		//Menu Vars
		public var home = new mainButton();
		public var products = new mainButton();
		public var support = new mainButton();
		public var contact = new mainButton();
		
                // This is the section that ASWC suggested but it's not working
		public function Website() {
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		public function init() {

			/* Set the Scale Mode of the Stage */
			//stage.scaleMode=StageScaleMode.NO_SCALE;
			//stage.align=StageAlign.TOP_LEFT;

			addChild(bg);
			addChild(title);
			addChild(footer);
			addChild(middle);

			var middleParam = {
			x:0,
			y:0.5,
			offsetX: 0,
			offsetY: -middle.height/2
			};
			new FluidObject(middle,middleParam);

			var footerParam = {
			x:1,
			y:1,
			offsetX: -footer.width - 10,
			offsetY: -footer.height -10
			};
			new FluidObject(footer,footerParam);

		}

		public function makeMenu() {

			addChild(home);

			var homeParam = {
			x:1,
			y:0,
			offsetX: -360,
			offsetY: 30};
			new FluidObject(home,homeParam);

			addChild(products);
			products.txt1.text="products";
			products.txtButtom.txt2.text="products";

			var productsParam = {
			x:1,
			y:0,
			offsetX: -260,
			offsetY: 30};
			new FluidObject(products,productsParam);

			addChild(support);
			support.txt1.text="support";
			support.txtButtom.txt2.text="support";

			var supportParam = {
			x:1,
			y:0,
			offsetX: -160,
			offsetY: 30};
			new FluidObject(support,supportParam);

			addChild(contact);
			contact.txt1.text="contact";
			contact.txtButtom.txt2.text="contact";

			var contactParam = {
			x:1,
			y:0,
			offsetX: -60,
			offsetY: 30};

			new FluidObject(contact,contactParam);

			home.buttonMode=true;
			home.useHandCursor=true;
			home.mouseChildren=false;

			products.buttonMode=true;
			products.useHandCursor=true;
			products.mouseChildren=false;

			support.buttonMode=true;
			support.useHandCursor=true;
			support.mouseChildren=false;

			contact.buttonMode=true;
			contact.useHandCursor=true;
			contact.mouseChildren=false;

			home.addEventListener("mouseOver", mouseRollOver);
			products.addEventListener("mouseOver", mouseRollOver);
			support.addEventListener("mouseOver", mouseRollOver);
			contact.addEventListener("mouseOver", mouseRollOver);

			home.addEventListener("mouseOut", mouseRollOut);
			products.addEventListener("mouseOut", mouseRollOut);
			support.addEventListener("mouseOut", mouseRollOut);
			contact.addEventListener("mouseOut", mouseRollOut);

			function mouseRollOver(e:MouseEvent) {

				var easingFunc=Back.easeOut;
				//how quickly the bottom text comes up
				var ysa=30;
				var yfa=-5;
				var duration=0.5;
				var myTween:Tween=new Tween(e.target.txtButtom,"y",easingFunc,ysa,yfa,duration,true);

				var easingFunc2=Regular.easeOut;
				var ysa2=-16.3;
				var yfa2=-70;
				var duration2=0.5;
				var myTween2:Tween=new Tween(e.target.txt1,"y",easingFunc2,ysa2,yfa2,duration2,true);
			}

			function mouseRollOut(e:MouseEvent) {

				var easingFunc3=Regular.easeOut;
				var ysa3=-5;
				var yfa3=30;
				var duration3=0.5;
				new Tween(e.target.txtButtom,"y",easingFunc3,ysa3,yfa3,duration3,true);

				var easingFunc4=Regular.easeOut;
				var ysa4=-46;
				var yfa4=-16.3;
				var duration4=0.5;
				new Tween(e.target.txt1,"y",easingFunc4,ysa4,yfa4,duration4,true);
			}
		
		}
	}
}
Put it all together and:


ArgumentError: Error #1063: Argument count mismatch on Website/init(). Expected 0, got 1.

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Middle/frame1()


Which is a lot fewer error than I originally got. Any help would be much appreciated.
stalkio is offline   Reply With Quote
Old 07-08-2010, 04:22 AM   #6
abeall
Senior Member
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 2,796
Send a message via AIM to abeall
Default

Since init() is an event handler, it will receive an event object as an argument, like all event handlers do:

ActionScript Code:
public function init(e:Event) {
__________________
Aaron Beall | Flash portfolio | Fireworks extensions | Twitter
abeall is offline   Reply With Quote
Reply


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 04:09 PM.

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