08.15.07
Flash CS3 / Flex Error #1009: Cannot access a property or method of a null object reference
TypeError: Error #1009: Cannot access a property or method of a null object reference
ActionScript 3 Error #1009 is an AS3 that you can get for many anecdotal reasons. This error basically means that you are trying to reference something that isn't there yet. That something can be a variable, data from the server, or even a movieClip or other display instance. So if you try and make a call to something and are getting this error simply look at what you are trying to reference and ask yourself is it there yet.
Don't bang your head against the wall any longer. Here I explain one of the most un-obvious ways to get this error.
One reason that you will get AS3 Error #1009 is because you are trying to access a movieClip that isn't instantiated yet. For example you try and reference a movieClip named loader_mc that is inside another movieClip. you are referencing it from a class that you created. Each time you run the test the movie you get the Run-Time Error #1009. You look inside your movieClip and see that the loader_mc is right where you want it. It is on frame 10 inside your animated moveiClip. That is when it dawns on you that the call to loader_mc happens when it is instantiated. Simply, put loader_mc on frame 1 and change it's alpha to 0 and then the movieClip will be instantiated when the call from your custom class is made.
Another reason for this error is simply incorrect targeting. If you target parent.bob and the correct reference is parent.parent.bob then you will get this error as well.
Fix 1 :
Make sure the the reference is instantiated before it is called. This means that the script is run after the object is loaded or the frame in the animation has been reached etc...
Fix 2 :
Check your targeting
Thanks and Happy Flashing
Nate said,
August 24, 2007 at 2:13 pm
I’m new to Flash, and I can’t quite figure out why I would be getting this 1009 error. Do you have any ideas why I might be getting the error with the following code?…
import flash.events.EventDispatcher;
import fl.video.*;
thePlayer.source = “splash.flv”;
var theCuePoint:Object = new Object();
theCuePoint.time = 0.001;
theCuePoint.name = “main_video”;
thePlayer.addASCuePoint(theCuePoint);
function splashCuePoint(evt:MetadataEvent):void {
loadVideo();
}
thePlayer.addEventListener(MetadataEvent.CUE_POINT, splashCuePoint);
function buttonClick(evt:MouseEvent):void {
loadVideo();
}
theButton.addEventListener(MouseEvent.CLICK, buttonClick);
function loadVideo():void {
thePlayer.source = “main_video.flv”;
thePlayer.play();
theButton.enabled = false;
theButton.visible = false;
}
Curtis J. Morley said,
August 27, 2007 at 5:32 pm
Nate,
According to your code you haven’t yet instantiated ‘thePlayer’ or ‘theButton’., unless these are on your stage. If you comment out any of the lines that start with thePlayer. you will see that the error goes away. This may be the reason for the error.
Tell me how you have your Flash file set up so that I can help you debug a little better.
Thanks,
Curtis J. Morley
Nate said,
August 27, 2007 at 7:32 pm
I am using an invisible button to keep my main video from downloading, found here…
http://blog.sessions.edu/web-design/how-to-save-bandwidth-when-displaying-flash-video/
My goal is to make a video player that acts much like the one that YouTube uses. If you click on the image, the video will load, and if you click on the play button, the video will load.
I have an FLVPlayback component on the stage on the bottom layer, and an invisible rectangle button on the layer above, over the image portion of the FLVPlayback. The FLVPlayback is named “thePlayer”, and the invisible button is named “theButton”. The actions layer is above the other two, and each layer just has one frame.
To get the play button to work as I want it to, I have the FLVPlayback component first load the “splash.flv” file, which is just a still image. I then used ActionScript to add a cue point 0.001 seconds into the video. When the cue point hits, it then loads the actual video.
Nate said,
September 4, 2007 at 7:31 pm
A fix has been found right here…
http://www.quip.net/blog/2007/flash/how-to-save-bandwidth-flash-video
scottizzl said,
September 17, 2007 at 10:54 pm
thank you! =)
Josh said,
December 24, 2007 at 8:06 am
Error 1009 is probably the worst trash error EVER! It doesn’t tell you where the error is. It just says 1009 bla bla bla. I can take like the whole day to fix it. And it’s not because I did not know what I was doing, one moment there is no error, the next, it is there. And I never touched the code of the function that initiated the error. I was working on another part. I tried to block some codes in that function to narrow down where the error was and guess what, the error still appeared no matter what. My head is now bleeding and the wall is demolished and the error is still there.
CK said,
January 12, 2008 at 1:29 pm
If you use the mxml argument -verbose-stacktraces=true the error will also output the line number where the null pointer exception was thrown. Seems to be a huge time saver for me while developing.
Bojan said,
March 13, 2008 at 8:54 pm
i’m getting this error, because I try to access stage like this “stage.addEventListener(MouseEvent.MOUSE_MOVE, MouseListener);”, but I dont think this is right way to do, but cannot find answer anywhere. Can you help me?..
Curtis J. Morley said,
March 14, 2008 at 7:21 am
CK,
Great tip. Thanks for the comment.
Josh,
Sorry about the head trauma man. Often times commenting out code will give this error because it actually makes the value null. Be careful when commenting out code that you are not removing a value that is needed later in the code.
Bojan,
The syntax stage.addEventListener(MouseEvent.MOUSE_MOVE, MouseListener); is proper and will work by itself and the function MouseListener. It seems that the error is not on this line but rather somewhere else in the code. If you can give me more code I would be happy to help you out with it.
Thanks,
Curtis J. Morley
james said,
March 16, 2008 at 10:47 pm
I am getting this error and can’t figure it out. If anyone can help me it would be appreciated.
TypeError: Error #1009: Cannot access a property or method of a null object reference. at siter_fla::MainTimeline/siter_fla::frame1()
this error pops up when I enter code. I tested the code by itself in a different flash file and it works fine, but as soon as I add it to my website that has other code in it it stops working and I get this error.
here is the code I added
var myloader:Loader = new Loader();
fe1_btn.addEventListener(MouseEvent.CLICK, image1);
function image1(event:MouseEvent):void {
var request:URLRequest = new URLRequest(”1.gif”);
myloader.load(request);
addChild(myloader);
myloader.x=486;
myloader.y=198;
}
fe2_btn.addEventListener(MouseEvent.CLICK, image2);
function image2(event:MouseEvent):void {
var request:URLRequest = new URLRequest(”2.gif”);
myloader.load(request);
addChild(myloader);
myloader.x=486;
myloader.y=198;
}
Matthew said,
March 20, 2008 at 2:04 pm
Hi, I’m new to flash and new to action scripting. I have managed in the past to get a graphic as a button go to a url when pressed. BUt now I have decided to try and use Actionscript 3.0. This was mistake number 1 as it has removed the onPress value from the code, after about half an hour I have come up with the code which seems to work once then comes up with the 1009 error.
My code is as follows. I have also checked it for errors and it says there is none. I have also made sure that each handler has a different tag as to not get confused.
Just for you to know each of my images/buttons are labeled as section1 and so on up to 4.
this.section1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler1);
function mouseDownHandler1(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.mysite.com/”));
}
Matthew said,
March 20, 2008 at 2:18 pm
Update: the error I get exactly is:
Error #1009: Cannot access a property or method of a null object reference.
at banner_250×240_fla::MainTimeline/banner_250×240_fla::frame27()
kreish said,
March 26, 2008 at 8:29 am
help pls
at frame 1 i put these lines:
========================
btnTest.addEventListener(
MouseEvent.MOUSE_UP,
function(evt:MouseEvent):void {
gotoAndPlay(”Finish”);
}
);
stop();
========================
what if btnTest is on Frame5?
what will i do to put all AScodes in single frame but then can access symbols or instance names that will load at later frames?
I do not want to put AS codes where and exaclty the btn will appear.
thank u
Ramesh Sakibanda said,
March 28, 2008 at 4:11 am
Hi Matthew,
the reason is, you might not have assigned a variable name to section1
i.e if you included above script in a frame and that frame *should have* an Object with instance name section1
thanks
ramesh
Bojan said,
April 12, 2008 at 1:28 pm
Hi again,
i’m trying in timeline to create new object witch will stop scene playing until I get mouse event(that is just for lerarning, easiest way for me I think).. Here is the code from timeline..
import vrnjci.uvod.*;
var zaDugme = new UlaznaKlasa();
Now, my way that I’m trying to do in constructor is to stop playing the scene, and listener for event like this..
package com.vrnjci.uvod {
import flash.display.*;
import flash.display.Stage;
import flash.events.*;
public class UlaznaKlasa extends MovieClip{
public function UlaznaKlasa(){
stop();
addEventListener(MouseEvent.MOUSE_MOVE, MouseListener);
}
public function Zavrsi():void{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, MouseListener);
}
private function MouseListener(e:Event):void{
trace(”RADI!!!!”);
}
public function Main():void{
}
}
}
I haven’t found much useful examples or books online, so any help would be largely appreciated :)..
Mady said,
May 5, 2008 at 7:01 pm
Hi guys,
I’m new to Flash & actionScript 3.0 I keep getting the same error as everyone
TypeError: Error #1009: Cannot access a property or method of a null object reference.at bhbHome_fla::MainTimeline/frame1()
I’m building a simple website and trying to control movies with “label frames”
the first code works fine the button “beer_btn” works fine but when I click on the lightH_btn” it doen’t work, I deleted this last button code and the error went away, which means that that’s where the problem is
If anyone can help me, it will greatly appreciated
Thanks
Mady
here is my code:
stop();
function playBeers(event:MouseEvent):void
{
this.gotoAndStop(”beers”)
}
function playLight(event:MouseEvent):void
{
gotoAndPlay(”light”)
}
arrowUM.beer_btn.addEventListener(MouseEvent.CLICK, playBeers);
lightH_btn.addEventListener(MouseEvent.CLICK, playLight);
Cam said,
May 8, 2008 at 9:28 am
Hi there Curtis… I am a huge fan of your site and I use it all the time, although this is my first comment. Most of the time I come to your site and I find it very helpful, usually reading your detailed descriptions of errors helps me figure out what is going on with my AS3 code… but Finally I have run into an issue which has completely stumped me! This is why I am posting on your site.
I have been working on an AS3 version of objects in 3d space, and I have based this on Paul Ortichanian’s version of the code ( http://reflektions.com/miniml/template_permalink.asp?id=459 ) which he developed in the main timeline of an FLA. I have ported the code over to a class, but for some reason I keep getting this error, #1009, which has pretty much become my arch nemesis! Is there any way I could get you to take a quick look at my code to see if you can spot whats wrong?…it would be greatly appreciated!
feel free to send me an email and I can send over the FLA etc.
Thanks so much for your help and great work with the site!… you are helping build the AS3 community through your generosity!
Flex Community Blog » Blog Archive » Flex/Flash TypeError: Error #1009: Cannot access a property or method of a null object reference said,
June 1, 2008 at 10:27 pm
[...] http://curtismorley.com/2007/08/15/flash-cs3-flex-error-1009-cannot-access-a-property-or-method-of-a... addthis_url = ‘http%3A%2F%2Fblog.flexcommunity.net%2F%3Fp%3D36′; addthis_title = ‘Flex%2FFlash+TypeError%3A+Error+%231009%3A+Cannot+access+a+property+or+method+of+a+null+object+reference’; addthis_pub = ”; [...]
curtismorley.com » Search Engine Optimization Example said,
June 2, 2008 at 5:51 pm
[...] Flex Error 1009 - #4 hit on Google [...]
Common ActionScript 3 Errors and Explanations | Jake Rutter - Designer and XHTML/CSS/ActionScript 3 Developer said,
June 11, 2008 at 10:58 am
[...] also come up with another great explanation as to what this actually means, you can read about it here. Share and Enjoy: These icons link to social bookmarking sites where readers can share and [...]
Denice said,
June 13, 2008 at 7:48 am
Hey.
I’m getting this error only when I use this script:
this.introfilmcontainer.skipknap_mc.buttonMode = true;
introfilmcontainer.skipknap_mc.addEventListener(MouseEvent.CLICK, skipknap);
function skipknap(e:MouseEvent):void {
introfilmcontainer.removeChild(introfilm);
gotoAndPlay(”intro”);
}
Its only when I actually USE it. When I don’t use the button everything’s fine…
What could be my problem?
Curtis J. Morley said,
June 13, 2008 at 7:55 am
Denice,
There are a couple of places that you can get this error. Which line of code is this error on?
Thanks,
Curtis J. Morley
Chris Brown said,
June 18, 2008 at 9:33 am
Working with external text in flash CS3 to create a website using external txt.
I am using menu buttons in the main stage to change text the main external text box. Everything works fine. I added a two buttons on the sections stage to change the the text in the external text box. and i get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at TAQA_fla::MainTimeline/frame1()
I have the buttons codes as:
sections.berry_btn.addEventListener(MouseEvent.CLICK,b8Listener);
sections.skinner_btn.addEventListener(MouseEvent.CLICK,b9Listener);
then:
function b8Listener(event:MouseEvent):void {
loadFile(”berry.txt”);
sections.gotoAndStop(”artist”);
}
function b9Listener(event:MouseEvent):void{
loadFile(”skinner.txt”);
sections.gotoAndStop(”skinner”);
}
Do you need to see the whole code. What do i need to get my buttons to work with out having them on the main stage.
Peter Kahuria said,
June 21, 2008 at 8:17 pm
Man, thanks alot! I have been scratching my head over this error and I was even considering going back to using AS 2.0.
I had movie clips inside another movie clip and your explanation really hit home.
Thank you again!
Curtis J. Morley said,
June 21, 2008 at 8:58 pm
Peter,
I am glad that this helps. It is worth the extra effort to get the benefits of AS3. Hopefully I will be of more help for you in te future.
Thanks,
Curtis J. Morley
Gianluca Bruno said,
July 8, 2008 at 4:11 pm
I am getting the 1009 error doing something a little differently from others. I have posted my question on the adobe forums, but haven’t able to get a response. I have a button click action:
The logon function
private function logon():void
{
userSession.userId = userId.text;
userSession.password = password.text;
var token:AsyncToken = UserSessionAssembler.createItem(userSession);
token.operation = “CREATE”;
}
The userSession object is being created in the init method, and that is being called on creationComplete
private function init():void
{
userSession = new UserSession();
}
The UserSession class is an actionscript class which I created and is mapped to a java class.
package assets.actionscript
{
[Bindable]
[RemoteClass(alias="UserSession")]
public class UserSession
{
public var userId:String;
public var password:String;
public var status:String;
public function UserSession()
{
}
public function getStatus():String {
return this.status;
}
public function setStatus(status:String):void {
this.status = status;
}
public function getUserId():String
{
return this.userId;
}
public function setUserId(userId:String):void
{
this.userId = userId;
}
public function getPassword(password:String):String
{
return this.password;
}
public function setPassword(password:String):void
{
this.password = password;
}
}
}
If I call the create method directly in the click function I can pass the object to the java class fine and it works, but for some reason when the object userSession is passed to the create method it throws the 1009 error. I have been stuck on this for a few days and has been very frusturating trying to resolve this.
Gianluca Bruno said,
July 8, 2008 at 4:12 pm
Sorry for some reason some of my code from the previous post did not submit
click=”logon()”
robert said,
July 10, 2008 at 4:42 am
hi,
I’m getting the 1009 error whie accessing the button instance. everything looks fine, and i can’t figure it out. here’s the code:
apps.addEventListener(MouseEvent.CLICK, clickapps);
function clickapps(event:Event):void{
trace(”apps”);
gotoAndStop(”apps”);
}
entrees.addEventListener(MouseEvent.CLICK, clickentrees);
function clickentrees(event:Event):void{
trace(”entrees”);
gotoAndStop(”entrees”);
}
this is the full error message:
apps
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::MovieClip@1ec786a1 to flash.display.SimpleButton.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at barcelona_fla::MainTimeline/barcelona_fla::frame10()
thanks for your help.
robert
Curtis J. Morley said,
July 10, 2008 at 6:43 am
Robert,
I tried your code with 2 movieClips on the stage in all frames. With your code the example works fine for me. Because of this I would assume (without being able to see your whole file) that a movieClip is not on the stage or something similar.
Actually, the second error may disappear if you resolve the first. It sounds like a movieClip is trying to be turned into a button.
Thanks,
Curtis J. Morley
eduardo said,
July 22, 2008 at 1:00 pm
can you tell me how do i aquire success on this function:
tryin to parse the tweener target dynamically
import caurina.transitions.*;
var countNumber;
var tgt:String;
function go():void {
for (count = 1; count < 10; count++) {
tgt = ‘e’ + conta;
Tweener.addTween(tgt, { ……. });
}
}
Scott said,
August 12, 2008 at 7:35 pm
Can anyone help me? I am very green at this and am just trying to do a simple, simple, simple flash site but I cannot get around this 1009 bug. It’s awful and stopping me from getting anywhere.
Basically how do you get the program to recognize the button as not null. I guess I mean how do you get it to read the button then apply the Action script in the proper order or vice versa whcih ever is correct. I can’t believe Adobe designed this flaw into the program. Horrible! And when i say simple I mean I don’t understand hardly any of the code above. I’m really depressed over this- ruining my efforts t get a site up- i’d made such good progress til now. Any help would be sooooo appreciated.
The code I am using is below:
stop();
FsAs.addEventListener(MouseEvent.CLICK, FestsAwards);
function FestsAwards(event:MouseEvent):void {
gotoAndPlay(4)
}
CsBs.addEventListener(MouseEvent.CLICK, ContsBios);
function ContsBios(event:MouseEvent):void {
gotoAndPlay(35)
}
Imgs.addEventListener(MouseEvent.CLICK, Images);
function Images(event:MouseEvent):void {
gotoAndPlay(61)
}
CstCrw.addEventListener(MouseEvent.CLICK, CastCrew);
function CastCrew(event:MouseEvent):void {
gotoAndPlay(111)
}
BlgNws.addEventListener(MouseEvent.CLICK, BlogNews);
function BlogNews(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.shores.blogspot.com/”));
}
David said,
August 28, 2008 at 7:19 am
There are times where I’ve set up listeners in the Class Constructor for objects that live directly on the stage which works fine, but have to slightly rework the Class to add them dynamically, as the listener in the Constructor is simply beating the object to the stage - therefore returning a null. I add an init() function and place my original listeners there, and add a listener to the constructor that fires when the object is actually available:
xPackage{
YClass extends Whatever{
public function YClass():void{
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init():void{
someObject.addEventListener(MouseEvent.MOUSE_DOWN, someFunction);
}
}
}
Hopes this helps some of you - it sure helped me.
Jeff said,
September 19, 2008 at 7:56 am
Hey,
I like your site. It is my first stop for understanding actionscript errors.
Regarding error 1009, I found that when loading external movie clips there is a problem with the timing of items being instantiated. A movie clip that worked fine on its own gave me this error when I loaded it into another swf.
My solution was to start a timer and run the offending function after a second or so… not that elegant but it works.
Here is an example of the timer:
public function addListenersTimer():void
{
var myTimer:Timer = new Timer(1000, 1);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, addListeners);
myTimer.start();
}
private function addListeners(e:TimerEvent):void
{
_dragger.addEventListener(MouseEvent.MOUSE_DOWN, onDraggerPress, false, 0, true);
_dragger.addEventListener(MouseEvent.MOUSE_UP, onDraggerUp, true, 0, true);
_dragger.stage.addEventListener(MouseEvent.MOUSE_UP, onDraggerUp, false, 0, true);
}
Thanks again,
Jeff
Curtis J. Morley said,
September 19, 2008 at 10:32 pm
Jeff,
Thanks for this great suggestion. One other thing that you can do is to listen for the COMPLETE event to fire and then assign the appropriate actions. Thanks for the compliments also. It is people like you that make writing like this worthwhile.
Thanks and Happy Flashing,
Curtis J. Morley
Jason said,
September 27, 2008 at 8:36 pm
Hello Mr. Morley,
I have a problem with the dreaded TypeError: Error #1009: Cannot access a property or method of a null object reference. I’m creating a flash website and I have the design layout already in flash. My movieclip buttons are not taking the playhead to the specified frame label. Here is the actionscript 3.0 code for just the portfolio movieclip button:
main_PORTFOLIO_button.buttonMode = true;
main_PORTFOLIO_button.addEventListener(MouseEvent.ROLL_OVER, portfolioOver);
main_PORTFOLIO_button.addEventListener(MouseEvent.ROLL_OUT, portfolioOut);
main_PORTFOLIO_button.addEventListener(MouseEvent.CLICK, portfolioClick);
function portfolioOver(event:MouseEvent):void
{
main_PORTFOLIO_button.main_PORTFOLIO_Animation.gotoAndPlay(”over”);
}
function portfolioOut(event:MouseEvent):void
{
main_PORTFOLIO_button.main_PORTFOLIO_Animation.gotoAndPlay(”out”);
}
function portfolioClick(event:MouseEvent):void
{
trace(”Clicked”);
gotoAndPlay(”portfolio”);
}
The frame label “portfolio” is on the main timeline. I want this movieclip button to go to the frame label “portfolio.” The problem comes about when I click the portfolio button to go the “portfolio” frame label. It goes to the specified frame label and outputs this error message:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Main3_fla::MainTimeline/portfolioOut()
If you can take a look at this I would really appreciate it.
Thanks.
Valerie Tucker said,
October 11, 2008 at 10:33 am
I keep on getting Error #1009 when I am on Facebook and playing Scrabble.
I press Dismiss all and the games disappear, so I press Continue and the same thing happens! Help!
Ashvin Menon said,
October 13, 2008 at 10:32 pm
i’m just curious, it’s an unrelated problem actually, but
i have a button that is actionscripted to play a movieclip. the thing is, the first frame of that movieclip has a stop(); command in it.
so my question is, will it play? which script takes higher priority? and if not, is there any way around this?
MELS said,
October 28, 2008 at 7:46 am
I came across Error #1009 in a big FLA:
I testet accesssing nested MovieClips and tell them something (e.g. gotoAndPlay). It’s no problem in my little test FLA. But in my project with long timelines, sounds and graphics, it just won’t work!!!
The FLA is is here:
http://www.id.uzh.ch/mels/projekte/zrm/rudi_test.fla
If you run it, you will see the rror and it will bring you to the code I’m talking about.
I have tried sooo many things, just nothing seems to work. Any suggestions?
elksie2500 said,
October 30, 2008 at 11:28 am
I came across Error #1009
while trying to build a remembrance flash package.
Essentially, I’m trying to recreate something I’ve seen on the MediaStorm website http://mediastorm.org/0024.htm a scrolling banner of images, each of which acts like a button to click through to a video player that I’ve managed to find.
But I’ve hit a problem with the error which is driving me mad.
The URL for the package is:
http://i.thisis.co.uk/274136/binaries/Remembrance9.fla
Curtis J. Morley said,
October 31, 2008 at 6:26 am
Elksie,
There are 2 things happening here that are giving you the error. The first is that you have a MOUSE_DOWN event that does a gotoAndStop(”Name”); and you also have a MOUSE_OUT event that changes the alpha. The MOUSE_DOWN happens while the object is still there. The MOUSE_OUT happens because you are no longer in the frame with that button.
So the MOUSE_OUT is trying to happen on an object that is no longer accessible to Flash because it is no longer on the timeline.
To fix this you can either just set a variable and then when you come back to the frame you can reset the alpha based off of that variable or you can change the event from a MOUSE_OUT to a MOUSE_UP like so
profilesMC.fence.kenBettany.addEventListener(MouseEvent.MOUSE_UP, mouseUpkenBettany);
Hope this helps and happy Flashing.
Curtis J. Morley
Vince said,
October 31, 2008 at 2:56 pm
Hello all! So, I’ve got an Error #1009 issue and would love a little guidance. On the first frame of my timeline, I have preloader animation that tracks the progress of the download. On the last frame of my timeline, I have a movie clip called INTRO_anim that loads after all of the content for my website. What I would like to be able to do is skip to the next frame of the timeline (which is where all the content is) once it’s ready and forget about playing the intro if I choose to do so. When I launch my swf and click on SKIP_btn, a bunch of 1009’s pop up along with some 1010’s. Here’s my code:
stop();
SKIP_btn.gotoAndStop(4);
START_btn.gotoAndStop(2);
SKIP_btn.buttonMode = true;
START_btn.buttonMode = true;
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
this.loaderInfo.addEventListener(Event.COMPLETE, onComplete);
function onProgress (event:ProgressEvent): void {
var loaded:Number = event.target.bytesLoaded;
var total:Number = event.target.bytesTotal;
var pct:Number = loaded/total;
LOADING_anim.gotoAndStop(Math.round(pct*100));
loaded_txt.text = “Loading Site… ” + (Math.round(pct*100)) + “%”;
if(framesLoaded >= 22) {
SKIP_btn.gotoAndStop(1);
SKIP_btn.addEventListener(MouseEvent.MOUSE_DOWN, SKIP_early_down);
SKIP_btn.addEventListener(MouseEvent.MOUSE_OVER, SKIP_early_over);
SKIP_btn.addEventListener(MouseEvent.MOUSE_OUT, SKIP_early_out);
loaded_txt.text = “Loading Intro…” + + (Math.round(pct*100)) + “%”;
function SKIP_early_down (event:MouseEvent): void {
this.loaderInfo.removeEventListener(Event.COMPLETE, onComplete);
nextFrame();
}
function SKIP_early_over (event:MouseEvent): void {
SKIP_btn.gotoAndStop(2);
}
function SKIP_early_out (event:MouseEvent): void {
SKIP_btn.gotoAndStop(1);
}
}
if(pct == 1) {
loaded_txt.text = “”;
}
}
function onComplete (event:Event): void {
SKIP_btn.gotoAndStop(1);
SKIP_btn.addEventListener(MouseEvent.MOUSE_DOWN, SKIP_down);
SKIP_btn.addEventListener(MouseEvent.MOUSE_OVER, SKIP_over);
SKIP_btn.addEventListener(MouseEvent.MOUSE_OUT, SKIP_out);
function SKIP_down (event:MouseEvent): void {
SKIP_btn.gotoAndStop(3);
nextFrame();
}
function SKIP_over (event:MouseEvent): void {
SKIP_btn.gotoAndStop(2)
}
function SKIP_out (event:MouseEvent): void {
SKIP_btn.gotoAndStop(1)
}
}
Any ideas? Thanks a lot for any help.
jabrat said,
November 3, 2008 at 9:27 am
var list:XML;
var items:XMLList;
var listPos:Number = 0;
var url:URLRequest = new URLRequest( “http://www.ccchuntersville.com/new/includes/getBannerAds.php” );
var loader:URLLoader = new URLLoader();
loader.addEventListener( Event.COMPLETE, onLoadComplete );
loader.load( url );
function onLoadComplete( event:Event ):void {
if( loader.data ) {
list = XML( loader.data );
items = list.item;
}
trace( list );
}
trace( list );
The first trace works fine, but the second does not. As soon as the function is exited it seems to reset list, why? Is there some scope problem I’m just not seeing. On the next frame I’m trying to access items but I get the 1009 error.
Curtis J. Morley said,
November 3, 2008 at 3:48 pm
Jabrat,
I see what you mean. The second trace comes back as null. This has an easy explanation for it. If you notice the second trace is output before the first trace. This is because the second trace executes before the Event.COMPLETE triggers.
So it is not resetting. The function is waiting for “loader” to get data where the trace that is not inside the function doesn’t wait and therefore you get the trace output before the data has arrived.
The data is there and it is accessible in frame 2 also as long as you have waited for the “loader” to get the data first. If this the only code in frame 1 and you try and access the “items” in frame 2 then it will not have been received yet and therefore Error 1009.
Try replacing your function with this code:
function onLoadComplete( event:Event ):void
{
if ( loader.data )
{
list = XML( loader.data );
items = list.item;
nextFrame();
}
trace( list );
}
stop();
Marlin Lopez said,
November 3, 2008 at 8:01 pm
Hello:
I am getting the same error: Error #1009: Cannot access a property or method of a null object reference. at FtScrollBar/checkSize() at FtScrollBar/LwJIyBI91212G2rSD7M351()
I am using a scrollbar component downloaded from Flashden.net
the weird thing is at first when movie is tested, button is clicked to access scene 3 which where I am having the problem it works perfect when sub buttons are selected, but if i go back after clicking other buttons to the previous then is when I get the error and scroll bar does not work.
Here is my actions script for all my buttons:
sinopsis_btn1.addEventListener(MouseEvent.MOUSE_DOWN, sinopsis_2Handler);
function sinopsis_2Handler(event:MouseEvent):void {
gotoAndPlay(1, “Scene 1″);
}
elenco_btn.addEventListener(MouseEvent.MOUSE_DOWN, elenco_2Handler);
function elenco_2Handler(event:MouseEvent):void {
gotoAndPlay(1, “Scene 2″);
}
edmundo_btn.addEventListener(MouseEvent.MOUSE_DOWN, edmundo_1Handler);
function edmundo_1Handler(event:MouseEvent):void {
gotoAndPlay(3, “Scene 3″);
}
luis_btn.addEventListener(MouseEvent.MOUSE_DOWN, luis_1Handler);
function luis_1Handler(event:MouseEvent):void {
gotoAndPlay(1, “Scene 3″);
}
stop();
mayra_btn.addEventListener(MouseEvent.MOUSE_DOWN, mayra_1Handler);
function mayra_1Handler(event:MouseEvent):void {
gotoAndPlay(4, “Scene 3″);
}
eric_btn.addEventListener(MouseEvent.MOUSE_DOWN, eric_1Handler);
function eric_1Handler(event:MouseEvent):void {
gotoAndPlay(5, “Scene 3″);
}
ivan_btn.addEventListener(MouseEvent.MOUSE_DOWN, ivan_1Handler);
function ivan_1Handler(event:MouseEvent):void {
gotoAndPlay(6, “Scene 3″);
}
jadit_btn.addEventListener(MouseEvent.MOUSE_DOWN, jadit_1Handler);
function jadit_1Handler(event:MouseEvent):void {
gotoAndPlay(7, “Scene 3″);
}
agustin_btn.addEventListener(MouseEvent.MOUSE_DOWN, agustin_1Handler);
function agustin_1Handler(event:MouseEvent):void {
gotoAndPlay(8, “Scene 3″);
}
sophie_btn.addEventListener(MouseEvent.MOUSE_DOWN, sophie_1Handler);
function sophie_1Handler(event:MouseEvent):void {
gotoAndPlay(9, “Scene 3″);
}
carola_btn.addEventListener(MouseEvent.MOUSE_DOWN, carola_1Handler);
function carola_1Handler(event:MouseEvent):void {
gotoAndPlay(10, “Scene 3″);
}
Saravana said,
November 5, 2008 at 4:00 am
Hi am getting the following error :
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fl.video::CuePointManager/dispatchASCuePoints()
at fl.video::FLVPlayback/http://www.adobe.com/2007/flash/flvplayback/internal::handleVideoEvent()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at fl.video::VideoPlayer/http://www.adobe.com/2007/flash/flvplayback/internal::doUpdateTime()
at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
at flash.utils::Timer/flash.utils:Timer::tick()
And below is my code :
package
{
import fl.video.FLVPlayback;
import fl.video.MetadataEvent;
import fl.video.CuePointType;
import fl.video.VideoEvent;
import flash.display.Sprite;
public class CuePointsTest1 extends Sprite {
private var videoPath:String = “rtmp://16.138.201.138/teststream/water.flv”;
private var cuePt:Object = new Object(); // create cue point object
public function CuePointsTest1() {
trace(’inside constructor’);
cuePt.time = 1;
cuePt.name = “ASCuePt1″;
cuePt.type = “actionscript”;
vDO.source = “rtmp://16.138.201.138/teststream/water.flv”;
vDO.skin = “SkinUnderAll.swf”;
vDO.skinBackgroundColor = 0×666666;
vDO.skinBackgroundAlpha = 0.5;
vDO.addASCuePoint(cuePt); //add AS cue point
vDO.addEventListener(MetadataEvent.CUE_POINT, cp_listener);
}
private function cp_listener(eventObject:MetadataEvent):void{
trace(’cue point occured’);
vDO.stop();
trace(’after Stop’);
vDO.removeEventListener(MetadataEvent.CUE_POINT, cp_listener);
vDO.source = “rtmp://16.138.201.138/teststream/clouds.flv”;
trace(’after source’);
vDO.removeASCuePoint(cuePt);
//vDO.play();
trace(’after play’);
vDO.addEventListener(VideoEvent.COMPLETE,onComp);
}
private function onComp(eventObject:VideoEvent):void{
trace(’Inside onComp’);
vDO.removeEventListener(VideoEvent.COMPLETE,onComp);
vDO.source = “rtmp://16.138.201.138/teststream/water.flv”;
vDO.seekSeconds(2);
vDO.play();
}
}
}
am new to ActionScript.
Please help me to solve this error.
with thanx and regards,
Saravanakumar
Aaron said,
November 5, 2008 at 2:41 pm
I’m having a problem with an download progress bar I have made. All of the instance names are unique, the layers are unique, the symbols are unique. The symbol seems to referenece the classes just fine. The problem is that I get this error, after I have initialized the symbol on the stage. The next command it recieves is to toggle the visibility of the download progress bar, which it carries out, but throws this type error 1009. This would not be a problem except that it will also throw the error on the webpage with CS4.
I’m still waiting on content for my site from my boss; however, the prototype functions except for this one Type Error.
I’ve been searching for answer a better part of two days now, any ideas?
The instance is named Download_Interface
the parent symbol is downloader_interface;
Frame 1
import com.ProjectControls.[ProjectControls;
import com.ProjectControls.Downloader.Downloader;
var Download_Interface:Downloader;
Download_Interface.disable();
var loaded:Number;
var total:Number;
var bar_mc:MovieClip = new MovieClip;
var loader_txt:TextField = new TextField;
this.addEventListener(Event.ENTER_FRAME, loading);
stop();
function loading(e:Event):void{
total = this.stage.loaderInfo.bytesTotal;
loaded = this.stage.loaderInfo.bytesLoaded;
bar_mc.scaleX = loaded/total;
loader_txt.text = “Loading: ” + Math.floor((loaded/total)*100)+ “%”+ ” Complete”;
if (total == loaded)
{
play();
this.removeEventListener(Event.ENTER_FRAME, loading);
}
}
ProjectControls.as
package com.ProjectControls
{
import flash.net.*;
import flash.events.*;
import flash.display.*;
import flash.text.*;
import com.ProjectControls.Downloader.Downloader;
public class ProjectControls extends MovieClip
{
}
}
package com.ProjectControls.Downloader
{
import flash.net.*;
import flash.events.*;
import flash.display.*;
import flash.display.MovieClip;
import flash.text.*;
import flash.utils.*;
import com.ProjectControls.ProjectControls;
public class Downloader extends ProjectControls
{
public var progressTXT:TextField;
public var progress_MC:MovieClip;
public var encasement_MC:MovieClip;
public var cancelBTN:SimpleButton;
public var insertedMyFileReference:FileReference = new FileReference;
public var myrequest:URLRequest;
public var TotalByteSize:Number;
public var DownloadedByteSize:Number;
public function disable():void
{
encasement_MC.visible = false;
progress_MC.visible = false;
progressTXT.text = ” “;
cancelBTN.visible = false;
}
public function downloadEvent(MyFileReference, myrequest):void
{ enableInterface();
insertedMyFileReference = MyFileReference;
insertedMyFileReference.addEventListener(ProgressEvent.PROGRESS, progressHandler);
insertedMyFileReference.addEventListener(Event.COMPLETE, completeHandler);
insertedMyFileReference.download(myrequest);
}
public function enableInterface():void
{
cancelBTN.visible = true;
progressTXT.visible = true;
progressTXT.text = “PREPARING DOWNLOAD”;
cancelBTN.enabled = true;
progress_MC.visible = true;
encasement_MC.visible = true;
cancelBTN.addEventListener(MouseEvent.CLICK, CancelDownload);
}
/**
* While the file is downloading, update the progress bar’s status. it’s only text, gotta turn text into visual aid
**/
public function progressHandler(event:ProgressEvent):void
{
/*scale a bar via math of bytesloaded/bytestotal*/
TotalByteSize = event.bytesTotal;
DownloadedByteSize = event.bytesLoaded;
progress_MC.scaleX = DownloadedByteSize/TotalByteSize;
progressTXT.text = “Downloading: ” + Math.floor((DownloadedByteSize/TotalByteSize)*100)+ “%”+ ” Complete”;
}
public function completeHandler(event:Event):void
{
var timer = new Timer(5000,1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
timer.start();
progressTXT.text = “DOWNLOAD COMPLETE”
cancelBTN.enabled = false;
function onTimerComplete(event:TimerEvent):void
{
progressTXT.visible = false;
cancelBTN.enabled = false;
cancelBTN.visible = false;
encasement_MC.visible = false;
progress_MC.visible = false;
}
}
public function CancelDownload(event:MouseEvent):void
{
insertedMyFileReference.cancel();
var timer = new Timer(5000,1);
progressTXT.text = “DOWNLOAD CANCELLED”;
timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
timer.start();
function onTimerComplete(event:TimerEvent):void
{
progressTXT.visible = false;
cancelBTN.enabled = false;
cancelBTN.visible = false;
encasement_MC.visible = false;
progress_MC.visible = false;
}
}
}
}
Aaron said,
November 5, 2008 at 3:25 pm
I figured it out. my guess, the preloader prevented the object from initializing, and by moving Download_Interface.disable(); to the frame after the preloader, made everything work. Weird…
elksie2500 said,
November 13, 2008 at 2:46 pm
Curtis,
Thanks for your help. I’ve now got my package working. Cheers
Elksie.
cassie said,
November 16, 2008 at 1:34 pm
I have to use scenes for my project. I am getting this error code to.
My button to contacts works. but once it gets there is when i get the error code. here is my code
stop();
btnHome.addEventListener(MouseEvent.CLICK, goHome);
btnContact.addEventListener(MouseEvent.CLICK, goContact);
btnServices.addEventListener(MouseEvent.CLICK, goServices);
function goHome(event:MouseEvent):void {
gotoAndStop(203, “Scene 1″);
}
function goContact(event:MouseEvent):void {
gotoAndPlay(1, “Scene 2″);
}
function goServices(event:MouseEvent):void {
gotoAndStop(1, “Scene 3″);
}
Siah said,
November 22, 2008 at 2:53 pm
Howdy, getting the error in question and stuck.
Have a map style nav setup to scroll to different sections of a large movieclip and getting the error.
I have the mc’s that I’m trying to pull in set with the linkage on. Should I still have them on the stage with an alpha of 0 or something. Many Thanks:
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
var homeX:Number = 500;
var homeY:Number = 375;
var aboutX:Number = 1024.0;
var aboutY:Number = 768;
var mediaX:Number = -24;
var mediaY:Number = 768;
var newsX:Number = 1024.0;
var newsY:Number = -18;
var contactX:Number = 24;
var contactY:Number = 28;
var xTween:Tween;
var yTween:Tween;
var inTween:Tween;
var outTween:Tween;
xTween = new Tween(main_mc,”x”, Strong.easeInOut,main_mc.x,homeX,2,true);
yTween = new Tween(main_mc,”y”, Strong.easeInOut,main_mc.y,homeY,2,true);
inTween = new Tween(main_mc.home_mc, “alpha”, None.easeNone, 0,1,.5,true);
outTween = new Tween(main_mc.home_mc, “alpha”, None.easeNone, 1,0,.5,true);
xTween.addEventListener(TweenEvent.MOTION_FINISH,fadeIn);
xTween.addEventListener(TweenEvent.MOTION_START,fadeOut);
home_btn.addEventListener(MouseEvent.CLICK, navigate);
about_btn.addEventListener(MouseEvent.CLICK, navigate);
media_btn.addEventListener(MouseEvent.CLICK, navigate);
news_btn.addEventListener(MouseEvent.CLICK, navigate);
contact_btn.addEventListener(MouseEvent.CLICK, navigate);
function navigate(event:MouseEvent):void
{
if(event.target == about_btn)
{
setTween(aboutX,aboutY,main_mc.about_mc);
}
else if(event.target == media_btn)
{
setTween(mediaX,mediaY,main_mc.media_mc);
}
else if(event.target == news_btn)
{
setTween(newsX,newsY,main_mc.news_mc);
}
else if(event.target == contact_btn)
{
setTween(contactX,contactY,main_mc.contact_mc);
}
else
{
setTween(homeX,homeY,main_mc.home_mc);
}
}
function setTween(tweenX:Number,tweenY:Number, tweenMC:MovieClip):void
{
xTween.begin = main_mc.x;
yTween.begin = main_mc.y;
xTween.finish = tweenX;
yTween.finish = tweenY;
tweenMC.alpha = 0;
inTween.obj = tweenMC;
xTween.start();
yTween.start();
}
function fadeIn(event:TweenEvent):void
{
inTween.start();
outTween.obj = inTween.obj;
}
function fadeOut(event:TweenEvent):void
{
outTween.start();
}
xTween.stop();
yTween.stop();
inTween.stop();
outTween.stop();
Mike B. said,
December 11, 2008 at 11:30 pm
Hi Curtis,
Heeelp! I’m getting the dreaded 1009!
I’m trying to preload my main movie swf externally which has a doc class. The doc class controls a particle effect (the one we made in class) but it gives me the 1009 when it loads. If I comment out the particles “for” loop in the doc class I don’t get the error. I think it has something to do with the “stage” being passed into the ParticleLogo() function but I’m stumped. Is there a better way to do this then what I have below?
DOC CLASS CODE:
package
{
import flash.display.MovieClip;
public class Bohmanart extends MovieClip
{
public function Bohmanart():void
{
init();
trace(”doc class loaded”);
}
private function init():void
{
for (var i:uint = 0; i < 19; i++)
{
var myNewLogo:ParticleLogo = new ParticleLogo(stage);
myNewLogo.x = Math.random()*(stage.stageWidth-myNewLogo.width)+myNewLogo.width/2;
myNewLogo.y = Math.random()*(stage.stageHeight-myNewLogo.height)+myNewLogo.height/2;
myNewLogo.cacheAsBitmap = true;
addChildAt(myNewLogo, 0);
}
}
}
}
PRELOADER CODE:
var bohmanart:Loader = new Loader();
var req:URLRequest = new URLRequest(”bohmanart.swf”)
bohmanart.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, prog);
bohmanart.contentLoaderInfo.addEventListener(Event.COMPLETE, fin);
bohmanart.load(req);
function prog(e:ProgressEvent):void
{
var perc:Number = e.bytesLoaded / e.bytesTotal;
}
function fin(e:Event):void
{
removeChildAt(0);
addChild(bohmanart);
}
Scott Guthrie said,
December 13, 2008 at 6:02 pm
Hi Curtis,
I making a game in Flash CS3. I keep getting this error. Here’s the error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.at my_algebra_map_11_24_fla::MainTimeline/checkDoors()
and here is the function checkDoors:
function checkDoors(event:Event):void {
var doors:Array = new Array();
doors=[map.door1, map.door2, map.door3, map.door4];
if(character.hitTestObject(map.door1)) {
gotoAndStop(5);
}
if(character.hitTestObject(map.door2)) {
gotoAndStop(5);
}
}
I am lost as to how the code isn’t finding door1 and door2.
Any suggestions would be great!
thanks for the wonderful site,
Scott
Jasen Burkett said,
December 14, 2008 at 7:10 pm
Making a flash As3 form that takes the info entered and puts it into a mysql database by using php.
– the code –
stop();
usrPassword.displayAsPassword = true;
registerBtn.addEventListener(MouseEvent.CLICK, sdClicked);
function sdClicked(e:MouseEvent):void {
if (usrFName.text!=”" && usrLName.text!=”" && usrLogin.text!=”" && usrPassword.text!=”") {
var myData:URLRequest = new URLRequest(”mysite.php”);
myData.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables;
variables.usrFName = usrFName.text;
variables.usrLName = usrLName.text;
variables.usrLogin = usrLogin.text;
variables.usrPassword = usrPassword.text;
myData.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
function dataOnLoad(evt:Event) {
trace(evt.target.data.writing);
if(evt.target.data.writing==”Ok”) {
gotoAndStop(2);
} else {
status_txt.text = “Error in saving submitted data”;
}
}
loader.addEventListener(Event.COMPLETE, dataOnLoad);
loader.load(myData);
} else {
status_txt.text = “All fields are mandatory”;
}
}
– the error –
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at flash.net::URLLoader/onComplete()
So what the crap is wrong?
I am almost ready to throw flash in the toliet and go back to the basics and use striaght php.
any help is greatly needed
Giuseppe said,
December 20, 2008 at 4:43 am
Hello. I get this error but just if i’m dowloading the swf from a web server or I’m simulating the download in the authoring mode. I’ve got an onEnterFrame function and in the very earlier cycles it seems not able to find the .text property of a textfield wich is inside a movieclip attached from the libraryusing addChild(). I’m also sure that the addChild method is called before the onEnterFrame function starts. Any ideas? And, by the way, the error I see in my browser can be seen by anyone or just by developers? Thank you.
Phil said,
December 27, 2008 at 4:25 am
I get this error and I can’t figure it out. I am new to actionscript so please help me out. Here is my code:
import flash.events.MouseEvent;
import flash.display.MovieClip;
servicesbtn.addEventListener(MouseEvent.MOUSE_OVER,services);
function services(MouseEvent):void {
gotoAndStop(2);
}
servicesmask.addEventListener(MouseEvent.MOUSE_OVER,servgone);
function servgone(MouseEvent):void {
gotoAndStop(1);
}
Paul said,
December 31, 2008 at 11:37 am
Well, you can try two things…
a) It’s better to just assign an event that fires when the new SWF is finished loading… (instead of the OnEnter way)
ex.
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompletedFunction);
B) And try accessing your newly loaded variables like this…
localVar = MovieClip(myLoader.content).someVar;
The MovieClip() wrapper apparently is required here, or things get screwed up.
Good luck!
imjake9 said,
January 1, 2009 at 2:52 pm
Help! I’m being held hostage by error 1009!
Here’s the problem. I have a program I’m trying to make for AIR with flash. So far, it is only a basic text editor. Here’s my code:
import flash.filesystem.*
stop();
var defaultDirectory:File = File.documentsDirectory;
var stream:FileStream;
var currentFile:File;
openBTN.addEventListener(MouseEvent.CLICK, openFileFunction)
saveBTN.addEventListener(MouseEvent.CLICK, saveFileFunction)
saveAsBTN.addEventListener(MouseEvent.CLICK, saveAsFileFunction)
function openFileFunction(event:MouseEvent):void {
openFile(defaultDirectory)
}
function openFile(root:File){
var TXTFilter:FileFilter = new FileFilter(”Text (*.txt,*.htm,*.html)”,”*.txt;*.htm;*.html”)
root.browseForOpen(”Open”, [TXTFilter])
root.addEventListener(Event.SELECT, openFileSelected)
}
function openFileSelected(event:Event):void {
stream = new FileStream;
currentFile = defaultDirectory
stream.openAsync((currentFile as File), FileMode.READ)
stream.addEventListener(Event.COMPLETE, fileReadHandler)
}
function fileReadHandler(event:Event):void {
var txt:String = stream.readUTFBytes(stream.bytesAvailable);
stream.close();
MainTXT.text = txt
}
function saveFileFunction(event:MouseEvent){
saveFile()
}
function saveFile(){
if (currentFile){
if (stream != null){
stream.close()
}
stream.open(currentFile, FileMode.WRITE);
var txt:String = MainTXT.text
stream.writeUTFBytes(txt)
stream.close()
} else {
saveFileAs(defaultDirectory)
}
}
//*******************************************************************
//SaveAs
function saveAsFileFunction(event:MouseEvent){
saveFileAs(defaultDirectory)
}
function saveFileAs(root:File){
root.browseForSave(”Save As”)
root.addEventListener(Event.SELECT, saveAsFileSelected)
}
function saveAsFileSelected(event:Event):void{
currentFile = defaultDirectory
saveFile()
}
I have openBTN, saveBTN, and saveAsBTN on the stage. Also, it says my error is on line 41. This is inside the saveFile() function, on this line:
stream.open(currentFile, FileMode.WRITE)
What is wrong?
imjake9 said,
January 2, 2009 at 9:15 am
Also, MainTXT is a text field on the stage.
imjake9 said,
January 4, 2009 at 9:48 am
Oops, I figured it out. I forgot this line:
stream = new FileStream()
Ogre2020 said,
January 7, 2009 at 8:48 am
Ok, this should be EZ but I cant get it. i have a function that displays an image when a certain object is clicked. I want to remove the previous image when the next object is clicked but i cant seem to access it outside of the block that its in, as shown by the 2 trace methods… I just get the lovely ERROR#1009 on the trace outside of the if statement
function dispMain(bookInput:XML, curn:int):void {
if (swh1 == 0) {
var loader:Loader = new Loader();
var loaderMain:MovieClip = new MovieClip();
loaderMain.mouseChildren = false;
loaderMain.addChild(loader);
this.addChild(loaderMain);
loaderMain.name = “loadmain”;
var loader2:Loader = new Loader();
var loadMask:MovieClip = new MovieClip();
loadMask.mouseChildren = false;
loadMask.addChild(loader2);
this.addChild(loadMask);
loadMask.name = “stageMask”;
loader2.load(new URLRequest(”http://www.squisheesoft.com/images/clearfix.png”));
loadMask.x = 20;
loadMask.y = 100;
loadMask.scaleX = 60;
loadMask.scaleY = 100;
loaderMain.mask = loadMask;
loader.load(new URLRequest(bookInput.Book.imageLG.text()[curn]));
loaderMain.x = 30;
loaderMain.y = 50;
loaderMain.scaleX = .5;
loaderMain.scaleY = .5;
//trace(curn);
loaderMain.addEventListener(MouseEvent.MOUSE_DOWN, mainDrag);
loaderMain.addEventListener(MouseEvent.MOUSE_UP, stopDr);
loaderMain.addEventListener(MouseEvent.MOUSE_OUT, stopDr);
trace (loaderMain.name);
swh1 = 1;
return;
}
swh1 = 0;
trace (loaderMain.name);
}
if you need the complete code, let me know
pomp said,
January 21, 2009 at 11:49 am
i am brand new to flash so pardon me if this is retarded. im trying to make a button which has a movieclip as its mouseover function work as a link to an external site. no matter what i do to the code the button remains non-functional and i get the 1009 error. please help
pure.addEventListener(MouseEvent.CLICK, pureitem)
function pureitem (evt) {
var url = “http://myweb.com/”
navigateToURL(new URLRequest(url))
}
stop();
Dan R said,
January 22, 2009 at 11:33 am
I am doing a Flash site where buttons are clicked and external SWFs load via “addChildAt (myLoader, 0)”. Each SWF that loads has on its first frame a preloader script and movie then the main content starts at frame 2. When the site loads, it loads home.swf into eec.swf (which contains navigation). No errors yet, until I load another SWF. No matter which SWF is loaded next, I get “TypeError: Error #1009: Cannot access a property or method of a null object reference. at home_fla::MainTimeline/PL_LOADING()”. My guess is this has something to do with navigation being in the parent (eec.swf) and the function being in a child (home.swf), but I can’t figure out how to fix it without breaking the loading SWF itself. Each SWF works correctly with no error by itself. Any help would be greatly appreciated.
Here is the eec.swf frame1 script which controls navigation:
stop();
import flash.display.*;
var myLoader:Loader = new Loader();
myLoader.load(new URLRequest(”home.swf”));
addChildAt(myLoader, 0);
function uiButton(event:MouseEvent):void {
//if home button is clicked
if (event.target==home_btn) {
if (currentLabel==”about”) {
gotoAndStop(”home”);
} else {
gotoAndStop(”home”);
removeChild(myLoader);
myLoader.load(new URLRequest(”home.swf”));
addChildAt(myLoader, 0);
}
}
//if New Construction button is clicked
if (event.target==newConstr_btn) {
if (currentLabel==”about”) {
gotoAndStop(”home”);
myLoader.load(new URLRequest(”newConstr.swf”));
addChildAt(myLoader, 1);
} else {
removeChild(myLoader);
myLoader.load(new URLRequest(”newConstr.swf”));
addChildAt(myLoader, 1);
}
}
//if Remodeling button is clicked
if (event.target==remodel_btn) {
if (currentLabel==”about”) {
gotoAndStop(”home”);
myLoader.load(new URLRequest(”remodel.swf”));
addChildAt(myLoader, 1);
} else {
removeChild(myLoader);
myLoader.load(new URLRequest(”remodel.swf”));
addChildAt(myLoader, 1);
}
}
//if Custom Builds button is clicked
if (event.target==custom_btn) {
if (currentLabel==”about”) {
gotoAndStop(”home”);
myLoader.load(new URLRequest(”custom.swf”));
addChildAt(myLoader, 1);
} else {
removeChild(myLoader);
myLoader.load(new URLRequest(”custom.swf”));
addChildAt(myLoader, 1);
}
}
//if About button is clicked
if (event.target==about_btn) {
removeChild(myLoader);
gotoAndPlay(”about”);
}
}
home_btn.addEventListener(MouseEvent.CLICK,uiButton);
newConstr_btn.addEventListener(MouseEvent.CLICK,uiButton);
remodel_btn.addEventListener(MouseEvent.CLICK,uiButton);
custom_btn.addEventListener(MouseEvent.CLICK,uiButton);
about_btn.addEventListener(MouseEvent.CLICK,uiButton);
Here is the frame 1 preloader script that is each SWF that is loaded:
stop();
import flash.display.*;
this.stop();
this.loaderInfo.addEventListener (ProgressEvent.PROGRESS, PL_LOADING);
function PL_LOADING(event:ProgressEvent):void {
var pcent:Number=event.bytesLoaded/event.bytesTotal*100;
bar_mc.scaleX=pcent/100;
loading_txt.text=”Loading - ” +int(pcent)+”%”;
if(pcent==100){
this.gotoAndPlay(2);
}
}
Dan R said,
January 22, 2009 at 1:14 pm
By the way, you can see the test site at http://www.rahmweb.com/eec.
Tod said,
January 31, 2009 at 11:18 pm
Hi
i have problem with #1009 error
———————————-
i wtached Object-Oriented Scrollbar: Part 2 video tutorial
http://www.gotoandlearn.com/play?id=72
source of tutorial:
http://gotoandlearn.com/files/oopscroll2.zip
———————————–
every thing is fine
but, when i load the swf to main.swf
- i can scrol the scroller, but not the content
- i got this error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.leebrimelow.ui::ScrollBar()
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at com.leebrimelow.ui::ScrollBox()
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.leebrimelow.ui::ScrollBox()
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
the scenario is:
- the main time line play and stop at 56.
- at 56 the main.swf loads the sec1.swf
any help please to fix this prob
Thanks in advance
Michiel said,
February 1, 2009 at 8:49 am
Hello Curtis J Morley,
I still have a problem with the TypeError: Error #1009: Cannot access a property or method of a null object reference in Flash Actionscript 3. Could you please help me?
I have several buttons,all of them on different keyframes with their own label tag (Page0, Page1, Page2, and so on). I have this code on my button in Page0 in my main time line actions layer:
button1.addEventListener(MouseEvent.CLICK, action1);
function action1(event:MouseEvent):void {
//click event
if(event.type == “click”){
gotoAndStop(”Page1″);
}
}
This button works, however: the addEventListener is not removed, it is still there when entering frame Page1! When I then try to hit button2 in frame Page1 to go to frame page2, it won’t work: the flash movie will not go to and stop at Page2, because the eventListener is still searching for button1, which is not on the stage anymore. Flash then gives me the null-object error.
So can you please tell me how to remove the addEventListener of button1 when the button is clicked and the flash movie goes to the frame Page1?
Thanks in advance!
Regards, Michiel (AS3 newbie)
StefanK said,
February 3, 2009 at 11:39 pm
The best 1009 advice on the whole wide web… thank you Mr. Morley!
Jimmy Yuan said,
February 4, 2009 at 6:32 pm
I keep getting the error whats wrong with it?
stop();
function goHome(e:MouseEvent):void {
gotoAndStop(”Home”);
}
Home_btn.addEventListener(MouseEvent.CLICK, goHome);
function goDivisions(e:MouseEvent):void {
gotoAndStop(”Divisions”);
}
Div_btn.addEventListener(MouseEvent.CLICK, goDivisions);
function goHistory(e:MouseEvent):void {
gotoAndStop(”History”);
}
History_btn.addEventListener(MouseEvent.CLICK, goHistory);
function goPhotos(e:MouseEvent):void {
gotoAndStop(”Photos”);
}
Photos_btn.addEventListener(MouseEvent.CLICK, goPhotos);
function goVideos(e:MouseEvent):void {
gotoAndStop(”Videos”);
}
Videos_btn.addEventListener(MouseEvent.CLICK, goVideos);
function goSponsors(e:MouseEvent):void {
gotoAndStop(”Sponsors”);
}
Sponsors_btn.addEventListener(MouseEvent.CLICK, goSponsors);
function goContact(e:MouseEvent):void {
gotoAndStop(”Contact”);
}
Contact_btn.addEventListener(MouseEvent.CLICK, goContact);
function goDesign(e:MouseEvent):void {
gotoAndStop(”Design”);
}
Design_btn.addEventListener(MouseEvent.CLICK, goDesign);
function goEngineering(e:MouseEvent):void {
gotoAndStop(”Engineering”);
}
Engineering_btn.addEventListener(MouseEvent.CLICK, goEngineering);
function goFinance(e:MouseEvent):void {
gotoAndStop(”Finance”);
}
Finance_btn.addEventListener(MouseEvent.CLICK, goFinance);
function goMarketing(e:MouseEvent):void {
gotoAndStop(”Marketing”);
}
Marketing_btn.addEventListener(MouseEvent.CLICK, goMarketing);
function goOperations(e:MouseEvent):void {
gotoAndStop(”Operations”);
}
Operations_btn.addEventListener(MouseEvent.CLICK, goOperations);
function goback(e:MouseEvent):void {
gotoAndStop(”back”);
}
back_btn.addEventListener(MouseEvent.CLICK, goHome);
Sponsors_btn.addEventListener(MouseEvent.CLICK, goSponsors);
Caitlin L said,
March 4, 2009 at 4:22 pm
If someone could help me out, I would be REALLY appreciative.
I’ve been banging my head against the wall for TOO long on this.
Essentially here’s how I’m set up.
- On the mainstage I have a control layer (play and stop) that can control an intro audio
- On the mainstage I also have a main movieclip for my menu.
- Everything else is within this main movieclip (instance: MCmenu)
- I’m externally loading all other pages (swf’s) via a load function, so that when the appropriate menu button is chosen, the proper swf is loaded into the viewing area designated on the stage.
- I’ll include my main coding below, but ALL of my buttons work except one within menu_mc. and I’m still getting the following error that WON’T go away.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MrpNewMenu_fla::MCmenu_3/frame1()
Here’s my coding for ALL of the other buttons…..
// create a new movie clip to hold loaded content
var contentHold:MovieClip = new MovieClip();
addChild(contentHold);
contentHold.x = 175;
contentHold.y = 100;
var swfHolder:MovieClip;
// Loading code
var myURLrequest:URLRequest = new URLRequest();
var myLoader:Loader = new Loader();
myLoader.contentLoaderInfo.addEventListener(Event.INIT, loadInitListen);
function loadInitListen($e) {
trace (”Loaded”);
if (contentHold.numChildren > 0) {
trace(”Num children ” + contentHold.numChildren);
for (var j = 0; j < contentHold.numChildren; j++) {
contentHold.removeChildAt(j);
}
}
swfHolder = MovieClip(myLoader.content);
contentHold.addChild(swfHolder);
}
// Menu code
menu_mc.addEventListener(MouseEvent.CLICK, menuClickListen);
function menuClickListen($e:MouseEvent):void {
switch ($e.target) {
//INFO FOR WOMEN SECTION
case menu_mc.info_mc.infosub_mc.whatgs_btn:
trace(”InfoWomen Loaded”);
myLoader.unload();
myURLrequest.url = “InfoWomen.swf”;
trace(myURLrequest);
myLoader.load(myURLrequest);
break;
//WOMEN AND SUBSTANCE USE SECTION
case menu_mc.women_mc.womensub_mc.wdiff_btn:
trace(”WomenDiff Loaded”);
myLoader.unload();
myURLrequest.url = “WomenandSubstances.swf”;
trace(myURLrequest);
myLoader.load(myURLrequest);
break;
/*case menu_mc.women_mc.womensub_mc.womenuse_btn:
trace(”Why Women Use Loaded”);
myLoader.unload();
myURLrequest.url = “WomenandSubstances.swf”;
myLoader.load(myURLrequest);
break;*/
//DIFF CATEGORIES OF DRUGS
case menu_mc.subclass_mc.diffcat_btn:
trace(”Diffcat Loaded”);
myLoader.unload();
myURLrequest.url = “SubstanceIntro.swf”;
myLoader.load(myURLrequest);
break;
//STIMULANTS
case menu_mc.subclass_mc.stim_mc.stimsub_mc.stimintro_btn:
trace(”Stim Intro Loaded”);
myLoader.unload();
myURLrequest.url = “Stim.swf”;
myLoader.load(myURLrequest);
break;
case menu_mc.subclass_mc.stim_mc.stimsub_mc.cocaine_btn:
trace(”StimBody Loaded”);
myLoader.unload();
myURLrequest.url = “StimBody.swf”;
myLoader.load(myURLrequest);
break;
case menu_mc.subclass_mc.stim_mc.stimsub_mc.crisk_btn:
trace(”StimRisk Loaded”);
myLoader.unload();
myURLrequest.url = “StimRisk.swf”;
myLoader.load(myURLrequest);
break;
//DEPRESSANTS
case menu_mc.subclass_mc.depress_mc.depsub_mc.depintro_btn:
trace(”Depress Intro Loaded”);
myLoader.unload();
myURLrequest.url = “Depress.swf”;
myLoader.load(myURLrequest);
break;
case menu_mc.subclass_mc.depress_mc.depsub_mc.heroinbody_btn:
trace(”Depress Body Loaded”);
myLoader.unload();
myURLrequest.url = “DepressBody.swf”;
myLoader.load(myURLrequest);
break;
case menu_mc.subclass_mc.depress_mc.depsub_mc.heroinrisk_btn:
trace(”Depress Risk Loaded”);
myLoader.unload();
myURLrequest.url = “DepressRisk.swf”;
myLoader.load(myURLrequest);
break;
//HALLUCINOGENS
case menu_mc.subclass_mc.hall_mc.hallsub_mc.hallintro_btn:
trace(”Hall Intro Loaded”);
myLoader.unload();
myURLrequest.url = “HallucinIntro.swf”;
myLoader.load(myURLrequest);
break;
case menu_mc.subclass_mc.hall_mc.hallsub_mc.hallbody_btn:
trace(”Hall Body Loaded”);
myLoader.unload();
myURLrequest.url = “HallucinBody.swf”;
myLoader.load(myURLrequest);
break;
case menu_mc.subclass_mc.hall_mc.hallsub_mc.hallrisk_btn:
trace(”Hall Risk Loaded”);
myLoader.unload();
myURLrequest.url = “HallucinRisk.swf”;
myLoader.load(myURLrequest);
break;
//PREGNANCY SECTION
case menu_mc.pregnancy_mc.pregsub_mc.baby_btn:
trace(”Baby Effects Loaded”);
myLoader.unload();
myURLrequest.url = “PregIntro.swf”;
myLoader.load(myURLrequest);
break;
case menu_mc.pregnancy_mc.pregsub_mc.fasd_btn:
trace(”FASD Loaded”);
myLoader.unload();
myURLrequest.url = “Fasd.swf”;
myLoader.load(myURLrequest);
break;
case menu_mc.pregnancy_mc.pregsub_mc.preghealth_btn:
trace(”Preg Health Loaded”);
myLoader.unload();
myURLrequest.url = “PregHealth.swf”;
myLoader.load(myURLrequest);
break;
//HEALTH PROMO SECTION
case menu_mc.health_mc.healthsub_mc.pain_btn:
trace(”Pain Management Loaded”);
myLoader.unload();
myURLrequest.url = “HealthPromo.swf”;
myLoader.load(myURLrequest);
break;
}
}
// Playback control
/*play_mc.addEventListener(MouseEvent.CLICK, playListen);
function playListen($e) {
swfHolder.play();
}
stop_mc.addEventListener(MouseEvent.CLICK, stopListen);
function stopListen($e) {
swfHolder.stop();*/
play_mc.addEventListener(MouseEvent.CLICK, playListen);
function playListen(event:MouseEvent):void {
swfHolder.play();
}
stop_mc.addEventListener(MouseEvent.CLICK, stopListen);
function stopListen(event:MouseEvent):void {
swfHolder.stop();
}
I have no idea why this is happening and really need a solution, as I’m not that advanced in coding.
Thanks in advance
Caitlin L said,
March 4, 2009 at 4:42 pm
Oh, and if it helps at all,
the button that’s not working gives me this error whenever I try to click on it upon export
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MrpNewMenu_fla::MainTimeline/menuClickListen()
Garrett said,
March 5, 2009 at 3:47 pm
Hello Curtis,
This has been killing me for over a week. After searching the web I landed here. This is the best explanation that I’ve seen yet. But my problem seems to be compounded. Let me try to briefly explain.
I have a simple VR, with a scroller that moves a plane back and forth. Works good. I have Nodes that animate on the plane that call out specific information about those parts. The Nodes cannot be on all the time because the Nodes intersect. Giving false links.
This SWF is then loaded into a main file that loads up text and video depending on the clicked Node.
I have the Scroller on the main timeline, with the Nodes and VR inside a MovieClip. I’m stuck and was hoping to find a solution that does not include going back to AS2.
Thanks in advance.
Garrett
matt said,
March 8, 2009 at 5:41 pm
i get this error when i use a code like this and go to another frame:
addEventListener(Event.ENTER_FRAME, movingEveryFrameFunctions);
function movingEveryFrameFunctions(event:Event):void{
jumper();
faller();
movingCollisionChecker();
mover();
if(leftRight == 2 && allreadyIns1 == false){
insCircle1.visible = false;
insCircle2.visible = true;
allreadyIns1 = true;
}
if(leftRight == 2 && spaceDown == true && allreadyIns2 == false){
insCircle2.visible = false;
insCircle3.visible = true;
allreadyIns2 = true;
}
//trace(leftRight);
}
don’t worry all variables and such are defined elsewhere. and i figured out that the ENTER_FRAME event keeps happening and executing that function
even while the frame is different and therefore, since the movieClips insCircle 1 through 3 don’t exist on the display list, the error comes up.
conan said,
March 18, 2009 at 6:44 pm
Thanks, Curtis!
Your example saved me hours of pulling out my hair and rewriting my (perfectly fine) code–I just put it in the wrong spot on the timeline.
guri said,
April 28, 2009 at 5:06 am
Hi,
I’m getting this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.at proces2_fla::MainTimeline/scrollPanel()
does anyone know what I doing wrong???
my code on scene is:
stop();
home_btn.addEventListener(MouseEvent.CLICK,clickHandler);
skræd_btn.addEventListener(MouseEvent.CLICK,clickHandler1);
filo_btn.addEventListener(MouseEvent.CLICK,clickHandler3);
acc_btn.addEventListener(MouseEvent.CLICK,clickHandler4);
matr_btn.addEventListener(MouseEvent.CLICK,clickHandler5);
forand_btn.addEventListener(MouseEvent.CLICK,clickHandler6);
function clickHandler(event:MouseEvent):void{
navigateToURL(new URLRequest(”http://www.e41364.monline.dk/forside.html”),”_self”);
}
function clickHandler1(event:MouseEvent):void{
navigateToURL(new URLRequest(”http://www.e41364.monline.dk/skraedderi.html”),”_self”);
}
function clickHandler3(event:MouseEvent):void{
navigateToURL(new URLRequest(”http://www.e41364.monline.dk/filosofi.html”),”_self”);
}
function clickHandler4(event:MouseEvent):void{
navigateToURL(new URLRequest(”http://www.e41364.monline.dk/accos.html”),”_self”);
}
function clickHandler5(event:MouseEvent):void{
navigateToURL(new URLRequest(”http://www.e41364.monline.dk/matr.html”),”_self”);
}
function clickHandler6(event:MouseEvent):void{
navigateToURL(new URLRequest(”http://www.e41364.monline.dk/foran.html”),”_self”);
}
panel.addEventListener(MouseEvent.MOUSE_OVER, panelOver);
function panelOver(event:MouseEvent):void{
panel.removeEventListener(MouseEvent.MOUSE_OVER, panelOver);
panel.addEventListener(Event.ENTER_FRAME, scrollPanel);
}
var b:Rectangle = stroke.getBounds(this);
function scrollPanel(event:Event):void{
if(mouseX b.right || mouseY b.bottom) {
panel.removeEventListener(Event.ENTER_FRAME, scrollPanel);
panel.addEventListener(MouseEvent.MOUSE_OVER, panelOver);
}
if(panel.x >= 235) {
panel.x = 235;
}
if(panel.x <= -480) {
panel.x = -480;
}
var xdist = mouseX - 450;
panel.x += -xdist / 5;
}
and in a movieclip I have this code:
thum1.addEventListener(MouseEvent.CLICK,gotoSt1);
function gotoSt1(event:MouseEvent):void{
MovieClip(root).gotoAndStop(”St1″);
}
thum2.addEventListener(MouseEvent.CLICK,gotoSt2);
function gotoSt2(event:MouseEvent):void{
MovieClip(root).gotoAndStop(”St2″);
}
thum3.addEventListener(MouseEvent.CLICK,gotoSt3);
function gotoSt3(event:MouseEvent):void{
MovieClip(root).gotoAndStop(”St3″);
}
thum4.addEventListener(MouseEvent.CLICK,gotoSt4);
function gotoSt4(event:MouseEvent):void{
MovieClip(root).gotoAndStop(”St4″);
}
thum5.addEventListener(MouseEvent.CLICK,gotoSt5);
function gotoSt5(event:MouseEvent):void{
MovieClip(root).gotoAndStop(”St5″);
}
Linda said,
May 12, 2009 at 2:12 pm
Hello I keep receiving this actionscript error #1009. I do not know how it got there I let my 8 year play a game on the computer and since then this error now appears. Please help me get rid of it or find out where it came from. It also makes my screen blink on and off.
Pete said,
May 15, 2009 at 9:45 am
Thanks for this! I was getting the error ONLY when view the flash in Firefox. It didnt display it in the output window when I was working on it and didnt apear when using IE. Very weird. But including the MC in question through out and turning the opacity to 0% fixed it
Dave said,
May 18, 2009 at 4:43 am
Hi im getting this error in the following, please help - its driving me nutts!
//
// Copyright (c) 2008, the Open Video Player authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of the openvideoplayer.org nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// AkamaiConnection class AS3 Reference Player
//
// This class demonstrates use of the AkamaiConnection class
// in connecting to the Akamai CDN and in rendering and controlling
// a streaming video.
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.media.Video;
import fl.controls.Button;
import fl.controls.Slider;
import fl.events.SliderEvent;
import flash.external.ExternalInterface;
import org.openvideoplayer.events.*;
import org.openvideoplayer.net.*;
public class accommodation extends MovieClip {
// UI elements
private var _video:Video;
private var _bPlayPause:Button;
private var _bStopVid:Button;
private var _bFullscreen:Button;
private var _videoSlider:Slider;
private var _volumeSlider:Slider;
private var _timeDisplay:TextField;
private var _bufferingDisplay:TextField;
// Variables
private var _nc:AkamaiConnection;
private var _ns:OvpNetStream;
private var _dragging:Boolean;
private var _streamLength:Number;
// Constants - replace these with references to your own content
private const HOSTNAME:String = “cp23245.edgefcs.net/ondemand”;
private var FILENAME:String = “23245/mm/flvmedia/806/W/e/b/WebSafeAccomodation-201029?cid=806&aid=201029&afid=306727″;
// Constructor
public function accommodation():void {
addChildren();
initVars();
}
// Add the children to the stage
private function addChildren():void {
// Draw background
this.graphics.beginFill(0×000000);
this.graphics.drawRoundRect(0,0,898,393,0);
this.graphics.endFill();
// Add video
_video = new Video(898,393);
_video.x = 0;
_video.y = 0;
_video.height = 393;
_video.width = 898;
addChild(_video);
// Add playPause button
_bPlayPause = new Button();
_bPlayPause.width = 45;
_bPlayPause.label = “Pause”;
_bPlayPause.enabled = false;
_bPlayPause.x = 40;
_bPlayPause.y = 350;
//_bPlayPause.addEventListener(MouseEvent.CLICK,doStopVid);
_bPlayPause.addEventListener(MouseEvent.CLICK,doPlayPause);
addChild(_bPlayPause);
// Add Stop button
_bStopVid = new Button();
_bStopVid.width = 40;
_bStopVid.label = “Stop”;
_bStopVid.enabled = false;
_bStopVid.x = 90;
_bStopVid.y = 350;
_bStopVid.addEventListener(MouseEvent.CLICK,doStopVid);
//_bStopVid.addEventListener(MouseEvent.CLICK,doPlayPause);
//_bStopVid.addEventListener(MouseEvent.CLICK,doStopAnim);
addChild(_bStopVid);
// Add the video slider
_videoSlider = new Slider();
_videoSlider.width = 200;
_videoSlider.x = 140;
_videoSlider.y = 360;
_videoSlider.minimum = 0;
_videoSlider.enabled = false;
_videoSlider.addEventListener(SliderEvent.THUMB_PRESS,beginDrag);
_videoSlider.addEventListener(SliderEvent.THUMB_RELEASE,endDrag);
addChild(_videoSlider);
// Add the volume slider
//_volumeSlider = new Slider();
//_volumeSlider.width = 80;
//_volumeSlider.x = 250;
//_volumeSlider.y = 210;
//_volumeSlider.minimum = 0;
//_volumeSlider.maximum = 100;
//_volumeSlider.value = 80;
//_volumeSlider.enabled = false;
//_volumeSlider.addEventListener(SliderEvent.CHANGE,volumeHandler);
//addChild(_volumeSlider);
// Add the time display
var format:TextFormat = new TextFormat();
format.color = 0xFFFFFF;
format.font = “Verdana”;
format.bold = true;
_timeDisplay = new TextField();
_timeDisplay.x = 240;
_timeDisplay.y = 230;
_timeDisplay.width = 200;
_timeDisplay.defaultTextFormat = format;
//addChild(_timeDisplay);
// Add the buffering display
_bufferingDisplay = new TextField();
_bufferingDisplay.x = 140;
_bufferingDisplay.y = 340;
_bufferingDisplay.width = 200;
_bufferingDisplay.defaultTextFormat = format;
_bufferingDisplay.text = “Loading …”;
addChild(_bufferingDisplay);
}
// Handle the start of a video scrub
private function beginDrag(e:SliderEvent):void {
_dragging = true;
}
// handle the end of a video scrub
private function endDrag(e:SliderEvent):void {
_ns.seek(_videoSlider.value);
}
// Update the volume
private function volumeHandler(e:SliderEvent):void {
_ns.volume = _volumeSlider.value/100;
}
// Handles the playPause button press
private function doPlayPause(e:MouseEvent):void {
switch (_bPlayPause.label) {
case “Pause” :
_ns.pause();
_bPlayPause.label = “Play”;
break;
case “Play” :
_ns.resume();
_bPlayPause.label = “Pause”;
break;
}
}
// Handles the StopVid button press
private function doStopVid(e:MouseEvent):void {
var result:Boolean = ExternalInterface.call(’showhide’, ‘flash’);
_ns.pause();
}
//private function doStopAnim(e:MouseEvent):void {
//var result:Boolean = ExternalInterface.call(’zxcSlideShow’, ‘Tst,auto+’);
//}
// Initializes variables with starting values
private function initVars():void {
_dragging = false;
_nc = new AkamaiConnection();
_nc.addEventListener(OvpEvent.BANDWIDTH,bandwidthHandler);
_nc.addEventListener(OvpEvent.STREAM_LENGTH,streamlengthHandler);
_nc.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
_nc.addEventListener(OvpEvent.ERROR,onError);
_nc.connect(HOSTNAME);
}
// Handles a successful connection
private function connectedHandler():void {
trace(”Successfully connected using ” + _nc.actualProtocol + ” on port ” + _nc.actualPort);
// As soon as we are connected, we’ll measure the available bandwidth
_nc.detectBandwidth();
_ns = new OvpNetStream(_nc.netConnection);
_ns.addEventListener(OvpEvent.PROGRESS,progressHandler);
_ns.addEventListener(OvpEvent.COMPLETE,completeHandler);
_ns.addEventListener(NetStatusEvent.NET_STATUS,netStreamStatusHandler);
_ns.addEventListener(OvpEvent.NETSTREAM_METADATA,metadataHandler);
_ns.addEventListener(OvpEvent.NETSTREAM_CUEPOINT,cuepointHandler);
}
// Handles a successful bandwidth measurement
private function bandwidthHandler(e:OvpEvent):void {
trace(”The bandwidth is ” + e.data.bandwidth + “kbps and the latency is ” + e.data.latency + ” ms.”);
// Use the bandwidth value to decide which file to play.
if (e.data.bandwidth <= 100) {
trace(”Selected = 100kbs : named:” + FILENAME);
FILENAME = “23245/mm/flvmedia/806/W/e/b/WebSafeAccomodation2-201029?cid=806&aid=201029&afid=306729″;
} else if (e.data.bandwidth <= 300){
trace(”Selected = 300kbs : named:” + FILENAME);
FILENAME = “23245/mm/flvmedia/806/W/e/b/WebSafeAccomodation1-201029?cid=806&aid=201029&afid=306728″;
} else {
trace(”Selected = 500kbs : named:” + FILENAME);
FILENAME = “23245/mm/flvmedia/806/W/e/b/WebSafeAccomodation-201029?cid=806&aid=201029&afid=306727″;
}
_nc.requestStreamLength(FILENAME);
}
// Handles a successful stream length request
private function streamlengthHandler(e:OvpEvent):void {
_videoSlider.maximum = e.data.streamLength;
_streamLength = e.data.streamLength;
_video.attachNetStream(_ns);
_ns.play(FILENAME);
_bPlayPause.enabled = true;
_bStopVid.enabled = true;
_videoSlider.enabled = true;
_volumeSlider.enabled = true;
_ns.volume = .8;
}
// Updates the UI elements as the video plays
private function progressHandler(e:OvpEvent):void {
_timeDisplay.text = _ns.timeAsTimeCode + ” | ” + _nc.streamLengthAsTimeCode(_streamLength);
if (!_dragging) {
_videoSlider.value = _ns.time;
}
_bufferingDisplay.visible = _ns.isBuffering;
_bufferingDisplay.text = “Buffering: ” + _ns.bufferPercentage+”%”;
}
// Handles netstream status events. We trap the buffer full event
// in order to start updating our slider again, to prevent the
// slider bouncing after a drag.
private function netStreamStatusHandler(e:NetStatusEvent):void {
switch (e.info.code) {
case “NetStream.Buffer.Full”:
_dragging = false;
break;
}
}
// Handles NetConnection status events. The description notifier is displayed
// for rejection events.
private function netStatusHandler(e:NetStatusEvent):void {
trace(e.info.code);
switch (e.info.code) {
case “NetConnection.Connect.Rejected”:
trace(”Rejected by server. Reason is “+e.info.description);
break;
case “NetConnection.Connect.Success”:
connectedHandler();
break;
}
}
// Catches the end of the stream. Note that the OvpEvent.COMPLETE
// event should only be used to detect the end of streaming files. For progressive delivery,
// use the OvpEvent.END_OF_STREAM event.
private function completeHandler(e:OvpEvent):void {
_ns.pause();
_ns.seek(0);
_bPlayPause.label = “Play”; //changed play to stop
_bStopVid.label = “Hide”;
}
// Handles metadata that is released by the stream
private function metadataHandler(e:OvpEvent):void {
trace(”Metadata received:”);
for (var propName:String in e.data) {
trace(”metadata: “+propName+” = “+e.data[propName]);
}
}
// Receives all cuepoint events dispatched by the NetStream
private function cuepointHandler(e:OvpEvent):void {
trace(”Cuepoint received:”);
for (var propName:String in e.data) {
if (propName != “parameters”) {
trace(propName+” = “+e.data[propName]);
} else {
trace(”parameters =”);
if (e.data.parameters != undefined) {
for (var paramName:String in e.data.parameters) {
trace(” “+paramName+”: “+e.data.parameters[paramName]);
}
} else {
trace(”undefined”);
}
}
}
}
// Handles any errors dispatched by the connection class.
private function onError(e:OvpEvent):void {
trace(”Error: ” + e.data.errorDescription);
}
}
}
Owen said,
May 19, 2009 at 2:42 pm
Hi!
I have 8 buttons in my scene and here is my action code:
var pressed:Boolean = false;
var xBoton:int;
var yBoton:int;
this.btEmpresa1.addEventListener(MouseEvent.CLICK, onMouseClick);
this.btEmpresa1.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
this.btEmpresa1.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
this.btEmpresa2.addEventListener(MouseEvent.CLICK, onMouseClick);
this.btEmpresa2.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
this.btEmpresa2.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
this.btEmpresa3.addEventListener(MouseEvent.CLICK, onMouseClick);
this.btEmpresa3.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
this.btEmpresa3.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
this.btEmpresa4.addEventListener(MouseEvent.CLICK, onMouseClick);
this.btEmpresa4.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
this.btEmpresa4.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
this.btEmpresa5.addEventListener(MouseEvent.CLICK, onMouseClick);
this.btEmpresa5.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
this.btEmpresa5.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
this.btEmpresa6.addEventListener(MouseEvent.CLICK, onMouseClick);
this.btEmpresa6.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
this.btEmpresa6.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
this.btEmpresa7.addEventListener(MouseEvent.CLICK, onMouseClick);
this.btEmpresa7.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
this.btEmpresa7.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
this.btEmpresa0.addEventListener(MouseEvent.CLICK, onMouseClick);
this.btEmpresa0.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
this.btEmpresa0.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
function onMouseOver(event:MouseEvent){
Mouse.cursor = MouseCursor.BUTTON;
}
function onMouseOut(event:MouseEvent){
Mouse.cursor = MouseCursor.ARROW;
}
function onMouseClick(event:MouseEvent){
var nombreBoton:String = event.target.name;
var frame:String = (nombreBoton.split(”bt”))[1];
var boton:MovieClip = root[nombreBoton];
trace(event.target.name)
if(!pressed){
xBoton = boton.x;
yBoton = boton.y;
hideDistnctButtons(nombreBoton);
moveBoton(boton);
gotoAndPlay(frame);
pressed = true;
}else{
showDistnctButtons(nombreBoton);
moveBackBoton(boton, xBoton, yBoton);
gotoAndPlay(”inicio”);
pressed = false;
}
}
function moveBoton(boton:MovieClip){
while(boton.x > 51.9){
boton.x = boton.x - 0.01;
}
boton.x = 51.9;
while(boton.y > 79.2){
boton.y = boton.y - 0.01;
}
boton.y = 79.2;
}
function moveBackBoton(boton:MovieClip, xBoton:int, yBoton:int){
while(boton.x < xBoton){
boton.x = boton.x + 0.1;
}
boton.x = xBoton;
while(boton.y < yBoton){
boton.y = boton.y + 0.1;
}
boton.y = yBoton;
}
function hideDistnctButtons(nombreBoton:String){
var aOcultar:String = nombreBoton.split(”btEmpresa”)[1];
for(var i=0; i<8; i++){
//trace(nombreBoton + ” ” + aOcultar + ” ” + i)
if(i != parseInt(aOcultar)){
(this[("btEmpresa"+i)]).visible = false;
}
}
}
function showDistnctButtons(nombreBoton:String){
var aOcultar:String = nombreBoton.split(”btEmpresa”)[1];
for(var i=0; i<8; i++){
//trace(nombreBoton + ” ” + aOcultar + ” ” + i)
if(i != parseInt(aOcultar)){
(this[("btEmpresa"+i)]).visible = true
}
}
}
Some times when I press a button, I get the error: TypeError: Error #1009: Cannot access a property or method of a null object reference
Could you help me to figure this out please?
Kali said,
May 21, 2009 at 8:39 pm
I have been getting this TypeError: Error #1009 for several months now at various Flash sites. It seems to happen randomly and at any site that has a lot of flash content, even simple ones like yahoo (with flash ads). It doesn’t happen on any other computer I go on, so I know it isn’t the sites. I’ve tried updating Flash, updating my browser, everything I can think of to get rid of it but just can’t seem to. I’ve done lots of forum searches, and seems that people normally experience this when working with there own Flash content, which I do not do. Any help is greatly appreciated.
Jerry said,
May 22, 2009 at 10:09 am
Thanks for explaining the error instead of just posting a random bit of code that won’t show the error
That seems to be what the rest of the internet resources do.
Lotsa love,
Jerry
gondai said,
May 25, 2009 at 6:21 am
i got this error too.. 2 days till now, me n my friend try to solve this eror…
we move the script and the button that have listener to the same layer at the same frame..
sometimes this is work.. i don’t know why this happen.. but not all this eror can use this method.. thats why i want know what is exactly the problem? script? or place of object?
my chse.. i compile the main scene.. there is no problem all of script is works, but when i compile the whle fla (include the intro scene) i got this eror(#1009) and make me to decided to sleep… why this happen again?? script? or scene?
scene intro and scene main is on the same .fla
Fluena - Web Design Serbia - Flash & more said,
May 25, 2009 at 8:11 am
So how do I reference, let’s say a button, that doesn’t appear in my first frame? Is there a way besides putting it to first frame and making it invisible?
dim said,
May 29, 2009 at 10:20 am
a had this type of error
i was trying to access to an method on another Class …. and this error pops
the problem was that i had and non existing variable in the method that i was trying to access
xenfreak said,
May 29, 2009 at 10:34 pm
wow, thanks for the advice on this. i was getting so annoyed that i couldn’t figure it out. what i did was i made a tween on an earlier frame and instantiated a movieclip after the tween, but didn’t instantiate the movieclips on the frame before the tween when i had made the alpha to 0. thanks for the assistance!
Ryan said,
June 7, 2009 at 2:50 pm
Thank you for writing your blog! I have been struggling with a script for a few days and I kept getting a ton of errors. I finally fixed everything today by trial and error except error #1009 and after I read your solution I fixed it! Thank you!
Eric said,
June 11, 2009 at 7:45 am
i, too, get the 1009 error. i’m trying to load googlemaps.swf. the code in main.swf is:
mapBtn.addEventListener(MouseEvent.CLICK, bringMap);
function bringMap(event:MouseEvent):void {
var mapLoader:Loader = new Loader();
var mapURL:URLRequest = new URLRequest(”googlemaps.swf”);
mapLoader.load(mapURL);
}
googlemaps.swf pulls data from events.xml file. the load function on the is:
var xmlLoader:URLLoader = new URLLoader();
var eventsData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest(”events.xml”));
function LoadXML(e:Event):void {
//some more code here
}
the exact error on main.swf is:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at googlemaps_fla::MainTimeline/LoadXML()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
any help is appreciated.
Eric said,
June 11, 2009 at 8:33 am
UPDATE:
i narrowed down my problem, and it doesn’t look its fit for this forum. it appears there’s a problems w/ Google Map’s setSize.
i eliminated all the code in the loadXML function to the bare minimum and if i put:
var map:Map = new Map();
map.key = “your_api_key”;
map.setSize(new Point(stage.stageWidth, stage.stageHeight));
this.addChild(map);
it WILL give me a map in googlemap.swf but WITH the 1009 error in main.swf
if i put:
var map:Map = new Map();
map.key = “your_api_key”;
map.width = 550;
map.height = 550;
this.addChild(map);
it WONT give me a map but it will load OK in main.swf
if anyone has ran into similar issue or knows a work around, i’d still appreciate some help
Thank you.
Eric said,
June 11, 2009 at 9:11 am
UPDATE: RESOLVED
i decided to put the map in a movie clip and the solved it
Thnx all.
Mathias said,
June 12, 2009 at 3:44 pm
yeah, thnx a lot, saved me quite some irritations and annoyance:)
Fernando said,
June 19, 2009 at 11:24 am
Thanks a very simple, but powerful tip, thanks so much.
Maureen said,
June 26, 2009 at 3:11 pm
I’m also “new” to Flash and am making animations for our landing pages. I have not had this error before. I have made several of these. But this time one of the graphics to be clicked on is of a “coupon” that is buried in our site. Click on the graphic (set to alpha 0 as it fades in) and it takes you to the place where it is kept on the site. I “tested” the movie and at first the page comes up…followed by the error message in the OUTPUT tab. Here is the code. Please help! Thank you, Maureen.
function gotoMASpecialsSite(event:MouseEvent):void
{
var maCouponURL:URLRequest = new URLRequest(”http://www.icomamerica.com/en/promotions/marine/SummerSavings/Default.aspx”);
navigateToURL(maCouponURL,”_blank”);
}
marineSavings_lp.addEventListener(MouseEvent.CLICK, gotoMASpecialsSite)
Mike W said,
June 29, 2009 at 1:49 am
Hi Curtis - thanks for the great advice on your weblog. I’m relatively new to CS4 / AS3 although I’ve been dabbling with Flash for a few years. Just a simple question wrt the original 1009 errors. Frame 1… When the AS3 is compiled at runtime along with the layers of the timeline, is there a specific order that the compilation takes place. My timeline only has one frame but 10 layers. I lay items out on the stage and give them instance names on the lower layers (bottom) and my AS3 is on the top layer. I still get 1009 errors. Does this have anything to do with the order of compilation of the layers? Thanks.