Solved

loading swf with document class attached

Posted on 2008-10-22
49
611 Views
Last Modified: 2016-08-29
How do I go about loading an external SWF with a document class attached into my non-document class SWF? I get the error: TypeError: Error #1009: Cannot access a property or method of a null object reference.
0
Comment
Question by:metallion1
  • 29
  • 18
49 Comments
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
we will need to see your classes pls.
0
 

Author Comment

by:metallion1
Comment Utility
I am trying to use the following code to access a swf, called windswept9.swf, that has a document class attached. The files are in a folder called "pickens" (attached).

var requestPickens:URLRequest = new URLRequest("pickens/windswept9.swf");
var PickensLoader:Loader = new Loader();
PickensLoader.x=136;
PickensLoader.y=126;
PickensLoader.load(requestPickens);

PickensLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, PickensLoaded);

function PickensLoaded(myevent:Event):void {
mPickensVidBox.alpha=0;
stage.addChild(PickensLoader);
}

The loader can't seem to access the .as file. I get this error message:

"TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at windswept9()"
 Do I need to do something with LoaderInfo perhaps?

Thanks very much for your help.
0
 

Author Comment

by:metallion1
Comment Utility
This file, "Ball.as" apparently wasn't included in the zip file I sent earlier. So I'm sending it here. Thanks
package {

	import flash.display.Sprite;

	

	public class Ball extends Sprite {

		public var radius:Number;

		private var color:uint;

		public var vx:Number = 0;

		public var vy:Number = 0;

		public var mass:Number = 1;

		

		public function Ball(radius:Number=40, color:uint=0xff0000) {

			this.radius = radius;

			this.color = color;

			init();

		}

		public function init():void {

			graphics.beginFill(color);

			graphics.drawCircle(0, 0, radius);

			graphics.endFill();

		}

	}

}

Open in new window

0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
there was no zip file either.
post it and if i get bored at work tomorrow i'll have a nosey round and see if see anything.
0
 

Author Comment

by:metallion1
Comment Utility
OK, I have put together a portfolio of my work in a Flash file. Clicking on buttons loads and displays my different pieces. One piece called "windswept9.swf" which is a Flash banner ad with a document class attached will not load. I get the error message "TypeError: Error #1009: Cannot access a property or method of a null object reference.at windswept9()." I am assuming that the main file that this swf is loaded into can't recognize the .as file. What do I have to do to load a swf file so that that its document class can be recognized?

Thanks a lot for your help.
Chuck
//this is the code for loading windswept9.swf
 

stop();
 

//This loads the windswept9.swf file located in the pickens folder. 
 

var PickensLoader:Loader = new Loader();

PickensLoader.contentLoaderInfo.addEventListener(Event.INIT/*COMPLETE*/, contentComplete);

PickensLoader.load(new URLRequest("pickens/windswept9.swf"));
 

function contentComplete(event:Event):void {

	

	addChild(PickensLoader);

	PickensLoader.x=136;

	PickensLoader.y=126;

}
 
 
 

//This is the document class associated with windswept9.swf
 

package {

	import flash.display.Sprite;

	import flash.display.MovieClip;

	import flash.display.StageScaleMode;

	import flash.events.Event;

	import flash.events.MouseEvent;

	import flash.media.Sound;

	import flash.media.SoundChannel;

	import flash.net.URLRequest;
 

	public class windswept9 extends Sprite {

		private var balls:Array;

		private var ball:Ball;

		private var numBalls:Number=2000;

		private var bounce:Number=-1;

		private var spring:Number=2.5;

		private var right:Number=425;

		private var bottom:Number=425;

		private var easing:Number=.99;

		private var vr:Number=70;

		private var centerScale:Number=2;

		private var range:Number=.6;

		private var speed:Number=.3;

		private var fan:Fan1;

		private var alph = -.2;

		private var Valph = 0;

		private var beghead:BegHead;

		private var BegHeadAngleX:Number = 0;

		private var BegHeadAngleY:Number = 0;

		private var BegHeadCenterX:Number = stage.stageWidth/2;

		private var BegHeadCenterY:Number = stage.stageHeight/2;

		private var BegHeadRange:Number = 10;

		private var BegHeadXspeed:Number = .1;

		private var BegHeadYspeed:Number = .2;

		private var wind:Sound;

		private var channel:SoundChannel;

		private var Test:test;
 

		public function windswept9() {

			init();

		}

		private function init():void {

			stage.scaleMode = StageScaleMode.NO_SCALE;

			balls=new Array;

			beghead = new BegHead();

			addChild(beghead);

			fan=new Fan1;

			addChild(fan);

			setChildIndex(fan, 2);

			fan.visible = false;

			wind = new Sound(new URLRequest("Wind.mp3"));

			Test = new test();
 
 

			//this creates an array of small particles and places them on the stage

			for (var i:uint=0; i < numBalls; i++) {

				ball=new Ball(2,0x750000);

				ball.x=Math.random() * stage.stageWidth;

				ball.y=Math.random() * stage.stageHeight;

				ball.vx=Math.random() * 6 - 3;

				ball.vy=Math.random() * 6 - 3;

				addChild(ball);

				balls.push(ball);

			}

			addEventListener(MouseEvent.MOUSE_OVER, BegHeadGone);

			addEventListener(Event.ENTER_FRAME, onEnterFrame);
 
 

		}

		private function onEnterFrame(event:Event):void {
 

			//this causes the headline to move randomly

			beghead.x = BegHeadCenterX + Math.sin(BegHeadAngleX) * BegHeadRange;

			beghead.y = BegHeadCenterY + Math.sin(BegHeadAngleY) * BegHeadRange;

			BegHeadAngleX += BegHeadXspeed;

			BegHeadAngleY += BegHeadYspeed;
 

			//this makes the fan visible until the mouse is moved over the stage and starts sound

			if (mouseX < right - 1 && mouseX > 1 && mouseY < bottom -1 && mouseY > 1) {

				fan.visible = true;

			}

			//this causes the fan to follow the mouse and ease to it

			var Fdx:Number=mouseX - fan.x * easing;

			var Fdy:Number=mouseY - fan.y * easing;

			var Fangle:Number=Math.atan2(Fdy,Fdx);

			fan.x+= Fdx;

			fan.y+= Fdy;

			//if (Fangle > 45 && Fangle <= 135 || Fangle  > -45 && Fangle <= -135) {
 

			//this causes the fan to rotate

			fan.bladebox.blade.rotation +=vr;
 
 

			//this moves the particles and causes them to wrap around the screen

			for (var i:Number=balls.length - 1; i > -1; i--) {

				var ball:Ball=Ball(balls[i]);

				ball.x+= ball.vx;

				ball.y+= ball.vy;

				if (ball.x > right && ball.alpha == 1.0) {

					ball.x=0;

				} else if (ball.x < 0 && ball.alpha == 1.0) {

					ball.x=right;

				}

				if (ball.y > bottom && ball.alpha == 1.0) {

					ball.y=0;

				} else if (ball.y < 0 && ball.alpha == 1.0) {

					ball.y=bottom;

				}

				//this keeps the particles from blowing away until the mouse is moved over the stage

				if (mouseX < right - 1 && mouseX > 1 && mouseY < bottom -1 && mouseY > 1) {

					//this determines the minimum distance between the x.y position of the fan and the x.y position of the particles

					var dx:Number=ball.x - fan.x;

					var dy:Number=ball.y - fan.y;

					var dist:Number=Math.sqrt(dx * dx + dy * dy);

					var minDist:Number=ball.radius + fan.width / 2;
 
 

					//when a particle collides with the fan, it springs away from it

					if (dist < minDist) {

						//ball.transform.colorTransform = new ColorTransform(4, 4, 4, 4, 200, 200, 200, 200);

						ball.alpha=0.9;

						var FanAngle:Number=Math.atan2(dy,dx);

						var tx:Number=fan.x + Math.cos(FanAngle) * minDist;

						var ty:Number=fan.y + Math.sin(FanAngle) * minDist;

						ball.vx+= tx - ball.x * spring;

						ball.vy+= ty - ball.y * spring;

					}

					//if a particle has collided with the fan and gone off the stage, it is removed

					if (ball.x > right && ball.alpha != 1.0 || ball.x < 0 && ball.alpha != 1.0 || ball.y > bottom && ball.alpha != 1.0 || ball.y < 0 && ball.alpha != 1.0 || balls.length < 30) {

						removeChild(ball);

						balls.splice(i,1);

					}

					if (balls.length < 1) {

						removeChild(fan);

						addChild(Test);

						Test.gotoAndPlay(1);

						removeEventListener(Event.ENTER_FRAME, onEnterFrame);

					}

				}

			}

		}

		private function BegHeadGone(event:MouseEvent):void {

			//this starts the wind sound

			channel = wind.play();

			//this removes the beginning headline when the mouse moves over the stage

			Valph += alph;

			beghead.alpha += Valph;

			if (beghead.alpha < .2) {

				removeChild(beghead);

				removeEventListener(MouseEvent.MOUSE_OVER, BegHeadGone);

			}

		}

	}

}

Open in new window

0
 

Author Comment

by:metallion1
Comment Utility
P.S. This site can be seen at http://mydomain.com/

If you click the "WEB" button and then click the "Pickens Plan Banner Ad" button (It has the word "HOW" on it), you can see that it doesn't load.
0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
ok i still don't know where i am in terms of the big picture, but i don't think its a case of not loading the documentclass but rather a case of you're trying to access something before its instantiated.
so something in your constructor of the file thats being loaded
can't u upload your portfolio that you created.
opening your site results in many errors.

TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at Chuck17_fla::MainTimeline/FTDLoaded()
is the first one.

0
 

Author Comment

by:metallion1
Comment Utility
Thanks so much for your input. Can you tell me how you got that error message? Because that "FTD" part of the site (the button next to the "Pickens Plan Banner Ad" button) works fine. I haven't been able to send you any swf or fla files because the Expert's Exchange download feature doesn't allow those formats, so I'm not sure where that came from. It's only when clicking the "Pickens Plan Banner Ad" button in the site (http://mydomain.com) that the file which is supposed to load (windswept9.swf) doesn't load. Everything else in the site works.

I sent the code of the windswept9 file in my last comment. I can't figure out where in that code that the constructor isn't allowing me to upload that file to the main file Chuck17.fla. Can you see it?

Sorry to be so dense. Thanks again for your help.

 
0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
as soon as i ran the fla i got the error.
i have the files at home on my laptop, not at work. maybe  i set up something wrong.
how big are your files, if not too big add a .txt after all your fiiles and zip to upload

i.e flashfile.fla.txt
flashfile.swf.txt
file.xml.txt

i asked about letting these extensions through and they're thinking about it but i think it was a case of don't hold your breath.
might not have time tonight have a class till quite late but will delve tomorrow
nag me if i forget.
0
 

Author Comment

by:metallion1
Comment Utility
b-g,

Thanks again for your prompt reply. I am sending files with .txt attached. They are the main fla for the site which is "Chuck17.fla", and the files I'm trying to load: "windswept9.fla" and "windswept9.as" (there are some mp3 files that go with these that I'm not including). I hope it helps make more sense of things. Again, I'm not sure why you are getting the error, because the whole site works perfectly except for loading the "windswept9.swf". The actionscript that is attempting to load the windswept9 file can be found on frame 188 of the Chuck17.fla.

Thanks again for your help. Hope you have a good class.
Chuck17.fla.txt.zip
windswept9.as.txt
0
 

Author Comment

by:metallion1
Comment Utility
One more file
windswept9.fla.txt
0
 

Author Comment

by:metallion1
Comment Utility
"might not have time tonight have a class till quite late but will delve tomorrow
nag me if i forget."

um, nag?  :-)
0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
thanks did need that.
talk me through this. based on the files u've sent me.
i run Chuck 17. what am i supposed to click on?

i get duplicate variable errors.
then duplicat label errors.
the when i click on the Web link i get a null object reference for webout();
where's this windswept thingie?
0
 

Author Comment

by:metallion1
Comment Utility
Even with those errors you described, the web site works perfectly. The problem I run into is once you click the "web" link, which you did, the button that contains the word "HOW" in it and has the title, "Pickens Plan Banner Ad," doesn't work. It gives me the error message, "TypeError: Error #1009: Cannot access a property or method of a null object reference at windswept9()." It is supposed to load the "windswept9" swf (I sent you the .fla and .as files). It seems to load fine, but it doesn't seem to be reading the document file, "windswept9.as." I just need to know how to load the windswept9 swf, which contains a document class, from a frame of the Chuck17.swf, which doesn't have a document class, during runtime. I have searched my books and the forums for an answer, but am stumped. Thanks very much
0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
ok will get back to u
0
 

Author Comment

by:metallion1
Comment Utility
thx
0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
ok. i need all your other classes in order for me to compile and run this properly in order to try and help you debug.
when i run the file currently, i'm getting an error on Chuck17 of null reference on webout.
when i do the HOW link it plays doensn't throw any errors but also doesn't load the swf file. might be because i'm using my own file and its not compiling properly.
the Ball class can i have that?

0
 

Author Comment

by:metallion1
Comment Utility
Some of my files couldn't be sent through this system even though I put txt after them. It might be easier to just email them all to you. Can I do that? If you don't want put your email address here, I can give you mine and you can email me directly.
0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
ok just send the ball.as (so far that's all its complaining about)

when the EE admins aren't watching send to

b g i a t m a i l b o x d o t c o za

if i don't look at it tonight will do tomorrow.
0
 

Author Comment

by:metallion1
Comment Utility
Thanks
Ball.as.txt
0
 

Author Comment

by:metallion1
Comment Utility
I just got a notification that my files didn't get through to you. Must have gotten it wrong. My address is *email address removed*. send me a note.
0
 

Author Comment

by:metallion1
Comment Utility
b-g, are you still there?
0
 

Author Comment

by:metallion1
Comment Utility
It's now been over a week since we've been conversing and not only do we seem no closer to a solution, but I can't even get you to answer my emails. I am desperate to solve this problem. If you can't, or don't want to do help me, then please let me know so I can't try another avenue. I'm paying for this service. At this point, it's just plain rude not to even acknowledge my emails.
0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
hi sorry i been finishing up some stuff for work and then over the weekend i left my phone at work so no 3G for internet connection.
i've been trying and no luck so far.
i have your files that you uploaded.
what i did do that was better was instead of using a load movie i did an addChild - but I don't know. i think there's something very basic we're both not seeing.
i'll keep trying but for now do a request attention and lets see if anyone else has any ideas.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:metallion1
Comment Utility
Did you get the "SITE copy.zip" file I sent through sendspace? I got a notification that it didn't go through. I think I might have gotten your email wrong.
0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
no i didn't receive anything.
how big is the zip file?
0
 

Author Comment

by:metallion1
Comment Utility
around 32 mb. Your email address didn't work. It got sent back to me. Can you try it again?
0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
32 meg. NO!!!
i'm poor like i use 3G and pay per MEG.
0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
instead of zipping it all up into one download would it be possible to make it individual downloads so i don't need to download the whole lot and only what i need as needed.
metallion, have you considered that the chance exists that we may not find a solution in the near future (not to say there is no solution) and you might need to reconsider how you're going about this
0
 

Author Comment

by:metallion1
Comment Utility
Thank you blue-genie. I have considered that, but I'm hoping that with all the files for which Netminder is is supplying the link, it will be easier. I have removed most irrelevant files so that the whole thing is much smaller.
0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
okies, no promises but i'm also curious about why it ain't working
0
 
LVL 5

Expert Comment

by:Netminder
Comment Utility
A file has been uploaded to EE-Stuff.com

Uploaded by : Netminder
Filename : SITE copy 2.zip
Size : 6,834,647 bytes
Comment : This file uploaded on behalf of metallion1.

You can download this file from https://filedb.experts-exchange.com/incoming/ee-stuff/7355-SITE-copy-2.zip

If other files are available for this question, then they can be accessed from https://filedb.experts-exchange.com/incoming/ee-stuff/7355-SITE-copy-2.zip
0
 

Author Comment

by:metallion1
Comment Utility
I'm rooting for you b-g. :-)
0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
haha thanks netminder.
0
 

Author Comment

by:metallion1
Comment Utility
If it helps, here is a restatement of the problem.

I am trying to load a swf which contains a document class, from a frame of another swf which doesn't contain a document class. The file seems to load fine, but the "loader swf" doesn't recognize the document class of the loaded swf. I have searched my books and the forums for an answer, but am stumped.

In the files provided by netminder in the link https://filedb.experts-exchange.com/incoming/ee-stuff/7355-SITE-copy-2.zip is a file called "Chuck17.fla." The swf for this plays a preloader, then stops on a page that has four buttons. Ignore any error messages.

The problem occurs when the "WEB" button is clicked. This brings up a page with five buttons at the top. When the first button, the one which contains the word "HOW" in it and has the title, "Pickens Plan Banner Ad," is clicked, it gives me the error message, "TypeError: Error #1009: Cannot access a property or method of a null object reference at windswept9()."

It is supposed to load a file called "windswept9.swf" from a folder called "pickens". It seems to load fine, but it doesn't seem to be reading the document class that goes with it, "windswept9.as." I just need to know how to load the windswept9 swf, which contains a document class, from a frame of the Chuck17.swf (frame 188), which doesn't have a document class, during runtime.

Thanks again very much for your attention.

0
 

Author Comment

by:metallion1
Comment Utility
So blue-genie, what do you think? Any ideas?
0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
ok, after much fiddling I think i've pinpointed the problem. i tried adding your external classes to the source path, anything and everything i could think of.
the problem that is throwing the null error is references to stage. if i comment those out or replace StageHeight / 2 with 500 for example - no problem.
i'm wondering if there's some confusion in the display list.
0
 

Author Comment

by:metallion1
Comment Utility
Thanks a lot b-g. I will check that out.
0
 

Author Comment

by:metallion1
Comment Utility
blue-genie, you do appear to be a genius. After taking out references to Stage, I got the file to load. Thanks!
However, I am getting the error messages:

Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.
      at windswept9/init()
      at windswept9()

ArgumentError: Error #2068: Invalid sound.
      at flash.media::Sound/play()
      at windswept9/BegHeadGone()

Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.
      at test/frame35()

These must have to do with two mp3s that I are also trying to load with the file.
"test" is a movie clip in the library of windswept9.fla.

What do you think I should do?



0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
um you might like me answer.
i've been reading up on the whole Stage stage debacle, and according to my mentor Colin Moock (he thinks i'm a stalker) the stage always refers to the base document class even for swf files that are loaded into the base file.

i'm thinking and I might well be wrong with this, you're not incoporating good OOP practice in the current structure you have (and you have way too many frames :-) )

i can imagine trying to create all those animations with classes would be a nightmare, and lots of errors abound before it comes right.
what i would do is first fix those other runtime errors you're getting.
then in terms of ioerrors, but in a listener for that, do it in a try catch
i'm not sure what's up with the sound.
i need to work on a prototype for a client this weekend so i'm not going to have too much time, but fiddle, and I"ll fiddle when i do have time and let's see if we can put this fella to bed.


0
 

Author Comment

by:metallion1
Comment Utility
I have been a fan of Colin Moock's since I read Essential Actionscript. I have to admit that I am completely self-taught, so it's certainly very possible that my OOP is something less than perfect. I'm primarily a graphic designer so this programming is way out of my comfort zone. I certainly do appreciate your help.

I'm not sure what a try catch is, but I will try to find out. Would you happen to have any good recommendations for videos or other ways to learn this stuff?

Good luck over the weekend. Look forward to hearing from you.
0
 

Author Comment

by:metallion1
Comment Utility
OK, I figured out the sound problem. I had to take the mp3 files out of the pickens folder and put them in the same directory as Chuck17.swf.

Only two glitches remain. I no longer see the stage of windswept9.swf when it's loaded into Chuck17.swf. Must have to do with removing stage references.

And, while everything works in preview, windswept9.swf won't load when called online from the server. What's up with that?
0
 

Author Comment

by:metallion1
Comment Utility
OK, fixed the loading-from-the-server problem. Now I just need to get my stage background back. Perhaps I just need to draw a rectangle for the background?
0
 
LVL 39

Expert Comment

by:blue-genie
Comment Utility
the brown bit? that was set as the background colour right?
that's odd as a swf loaded usually retains that.
you have a very unique problem going on :-)
yeah try adding the background as a sprite.
0
 

Author Comment

by:metallion1
Comment Utility
Actually, the background is bright yellow. I don't know where it went. If you have a spare minute, you can see the windsept9.swf i was trying to load at http://mydomain.com. Just go through the same routine to get to the Pickens Plan banner ad button.

Thanks again for all your help. I really appreciate it.
0
 

Author Comment

by:metallion1
Comment Utility
P.S. Always nice to know that I'm unique. :-D
0
 
LVL 39

Accepted Solution

by:
blue-genie earned 500 total points
Comment Utility
i was reading CyanBlue's post and i wonder if thats maybe  a way to go it's about shared libraries.
i've never used shared libraries so i don't know.
here's his solutions
http://forums.devshed.com/flash-help-38/problems-with-export-for-runtime-sharing-542510.html
http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000217.html

it is gone :-( have no idea why it's gone, unless it was exported to be transparent maybe?
also as that animation rocks up there's an error about removeChild - i think try and get rid of all your runtime errors first and then go from there.

ps. check if you have export in first frame options ticked for stuff that doesn't need to be as your preloader only kicks in after about 20 seconds.
if stuff stops working after you've unchecked export for first frame (put it back) :-)

0
 

Author Closing Comment

by:metallion1
Comment Utility
Thanks b-g. I appreciate your time--and your help. Happy coding.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now