FORUMS: list search recent posts

Type 1009 error appears on btns in debug???

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Terrence Dunlop
Type 1009 error appears on btns in debug???
on Mar 11, 2009 at 7:44:14 pm

Hey all,

I have a simple loader that instansiated in the actions layer of the timeline after button instances fade in in the earlier frames. It waits for a btnClick and then loads a newSWF.

It keeps throwing a Type 1009 Error: cannot reference a null object.
It's so simple it's driving me up the wall!!

Here's the code:
Code:

var defaultSwf:URLRequest=new URLRequest("defaultHeadShot.swf");
var swfLoader:Loader=new Loader();
swfLoader.load(defaultSWF);
addChild(swfLoader);

var GalleryReq:URLRequest=new URLRequest("swfs/gallery.swf");

//////////////in the debug panel this line is pointed at as the gum-up.
gallery_btn.addEventListener(MouseEvent.CLICK, btnClick);

function btnClick(event:Event):void
{
removeChild(swfLoader);
var newSWFRequest:URLRequest=newURLRequest("swfs/"+event.target.name+".swf");
swfLoader.load(newSWFRequest)
addChild(swfLoader);
}


can anyone recommend a way to trouble shoot this? I'm pulling my hair out.

TD



Return to posts index

demetri tashie
Re: Type 1009 error appears on btns in debug???
on Mar 12, 2009 at 12:04:17 am

your problem might have been having your function being (event:Event) when it is a MouseEvent...

here is slightly different code that will do the trick: to initially load a first SWF, then upon a button click, it unloads and loads a second SWF. i have adopted it for a scenario as such:

a timeline with 3 buttons: Home , About, and Products. each button will control the unloading of the previous SWF, and loading of the new SWF. this will all happen in the same loader.


var homeRequest:URLRequest = new URLRequest("home.swf");
var aboutRequest:URLRequest = new URLRequest("about.swf");
var productsRequest:URLRequest = new URLRequest("products.swf");

var imageLoader:Loader = new Loader();
imageLoader.load(homeRequest);
addChild(imageLoader);


function home(evt:MouseEvent):void{
removeChild(imageLoader);
imageLoader.load(homeRequest);
addChild(imageLoader);
}
homeBTN.addEventListener(MouseEvent.CLICK, home);



function about(evt:MouseEvent):void{
removeChild(imageLoader);
imageLoader.load(aboutRequest);
addChild(imageLoader);
}
aboutBTN.addEventListener(MouseEvent.CLICK, about);



function products(evt:MouseEvent):void{
removeChild(imageLoader);
imageLoader.load(productsRequest);
addChild(imageLoader);
}
productsBTN.addEventListener(MouseEvent.CLICK, products);


review this code and it should make sense.

one difference in my code is that i am declaring all the new SWF URL requests outside the function whereas you were declaring the second one inside the function.

remember that if any of your externally loaded SWFs have video playing, that you would want to clear the SoundChannel or Sound Mixer on unload, otherwise the soundtrack to that video will keep playing.

good luck, let us know how it works for you


Return to posts index

Terrence Dunlop
Re: Type 1009 error appears on btns in debug???
on Mar 15, 2009 at 12:44:41 am

the solution was embarassing: in order for my nifty btnClick function to work, the button had to be called only "gallery" and not "gallery_btn." Take off the _btn suffix and it works great.

Here's my latest difficulty though with Type Error 1009, if you have any input I'd sure appreciate it:

I'm loading a photogallery swf into the swfLoader of my main page. This swf has its own loader, picLoader. I've traced it out, and the picLoader does get loaded into the swfLoader, but there its functionality seems to stop... it can't find the URLs of the photogallery's swfs.

Any advice?



Return to posts index


Stanley Silverman
Re: Type 1009 error appears on btns in debug???
on Mar 15, 2009 at 1:59:51 am

I have a similar problem, but know so little about ac 3.0 that I can't really debug my own problem...

Any help would be greatly appreciated!!

-Stanley


Here's the error that shows up in the OUTPUT panel:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at EmailThanksv3_fla::MainTimeline/typeChar()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()

Here the code:

var flickerOn:Boolean = false;
var letters:Array = new Array();
var timer:Timer = new Timer(20);
var betweenLines:String = "n";
var delay:uint = 0;
var typeText:String="Typewriter effect";

timer.addEventListener(TimerEvent.TIMER,typeChar);
timer.start();

function typeChar(e:TimerEvent):void {
if ((letters[0] == betweenLines && delay < 8) || letters.length == 0) {
delay++;
if (flickerOn) {
typed.text = typed.text.substring(0,typed.text.length - 1);
} else {
typed.appendText("_");
}
flickerOn = !flickerOn;
} else {
delay = 0;
typed.appendText(letters.shift());
}}
function type(theString:String):void {
letters.push(betweenLines);
for (var i = 0; i < theString.length; i++) {
letters.push(theString.charAt(i));
}}

type("PLEASE CLICK");
type("VERIFICATION LINK");


Return to posts index

demetri tashie
Re: Type 1009 error appears on btns in debug???
on Mar 15, 2009 at 3:48:27 am

Terrence-
it sounds to me like you are having an Inheritance issue : Parent - Child,Child of Child etc. ( a MovieClip within a MovieClip within a MovieClip etc) . i can't even keep track of the way you were describing it.

You can have as many MovieClips ( or "Loaders" ) inside of each other as you want, but you have to keep real clear the Inheritance/ 'Family Tree" relationship of each other. especially when you need to call from one Clip to control another clip.

and to control an externally loaded SWF from the main timeline( or from another externally loaded SWF) takes a few tricks to accomplish that. It is not the same as talking to a MC within another MC.

what functionality are you talking about not working? maybe if you clearly describe what you are trying to do, and clearly follow the path, it might become apparent. also,post your code so we can see what you are doing. let's see if we can figure your problem out !

the way i think you have it is this : a MainTimeline ( let's call it PAGE) with a swfLoader ( let's call it swfLoader1) so swfLoader1 will have an externally loaded PhotoGallery.swf . PhotoGaller.swf has it's own swfLoader2, which externally loads PicGallery.swf

everything loads, but there is no communication between them, eh ? from where are you calling, and to what target? best to clearly describe it, and post the code .....




Return to posts index

Terrence Dunlop
Re: Type 1009 error appears on btns in debug???
on Mar 17, 2009 at 7:13:25 pm

Yep, that's it, what you're describing. How is it done??? I've almost given up hope. If it's just an inheritance problem please help me correct it. I'm about to put it all in one long timeline but I really don't want to ...

As you guessed, I'm trying to control the buttons, and therefore the loading, of swfLoader2, from PAGE. PAGE loads the photogallery swf into swfLoader1, and then the user scrolls through photos using photogallery's buttons and its loader, swfLoader2.

It's all framed by the graphics of PAGE. PAGE is always in the background.
So now the code:

PAGE:

//// Loads the main page and its loader
var defaultPhotoRequest:URLRequest=new URLRequest("defaultPhoto.swf");
var swfLoader1:Loader=new Loader();
swfLoader1.load(defaultPhotoRequest);
addChild(swfLoader1);

////listener on the photogallery button, named "photogallery"
photogallery.addEventListener(MouseEvent.CLICK, btnClick);

////loads the gallery swf into swfLoader1
function btnClick(event:Event):void
{
removeChild(swfLoader1);
var newSWFRequest:URLRequest=new URLRequest("swfs/"+event.target.name+".swf");
swfLoader1.load(newSWFRequest)
addChild(swfLoader1);
swfLoader1.y=120;
}


Next, the photogallery's actionscript:

////photogallery's loader instantiated and loaded with a default photo.
var swfLoader2:Loader=new Loader();
var defaultGalleryPic:URLRequest=new URLRequest("gallShot.swf");
swfLoader2.load(defaultGalleryPic);
addChild(swfLoader2);

//button listener for "clippings" button
clippings.addEventListener(MouseEvent.CLICK, gallerybtnClick, false, 0, true);

/*same principle as the first page, only pointing to a different swf folder titled swiff, to avoid confusion*/

function gallerybtnClick(evt:Event):void
{
removeChild(swfLoader2);
var gallerySWFRequest:URLRequest=new URLRequest("swiffs/"+evt.target.name+".swf");
swfLoader2.load(gallerySWFRequest)
addChild(swfLoader2);
swfLoader2.y=25;
}




Return to posts index


demetri tashie
Re: Type 1009 error appears on btns in debug???
on Mar 18, 2009 at 2:58:27 am

ok - i think i am understanding, and this is not so hard to accomplish. you are unclear ( or i am not understanding) your buttons controlling what. i made a small bare-bones example. tell me if this is what you are trying to do ( but of course looking much nicer !), and if so, i can pass along the code for you, if not, we have something solid to talk about.

http://www.demetri-media.com/Sven/ExternalLoadGalleries/galleryGallery.swf

there are 3 SWFs : the main SWF ( which is the 'PAGE' . that SWF/PAGE has a Loader which will load 2 different galleries(2 different Externally Loaded SWFs). one is loaded by default. the main SWF/PAGE has 2 buttons to let you choose which gallery you want: gallery 1 or gallery 2. ( i threw in some disabling of the buttons depending on which gallery is loaded)

the Default gallery has 1 loader, and 3 buttons, which will externally load 3 pictures. the second gallery also has 3 buttons to externally load 3 other images

IF this is the idea of what you want to do, then the buttons actually DO NOT communicate across from one SWF to another.

let me know, and let's take it from there.


Return to posts index

Terrence Dunlop
Re: Type 1009 error appears on btns in debug???
on Mar 18, 2009 at 7:20:04 am

This is what I'm interested in. Could you send me the code? I'm assuming both gallery 1 and gallery 2 have their own loaders, located in their respective swfs. Correct?

The other difficulty I'm finding is this: with the project I have taken over, the menus for each gallery swf "animate-in" using tweens in a flash timeline. The client wants to keep these and I sure don't want to have to do all that work over using code alone - but I wonder if my error messages have something to do with these timelines within the gallery swfs. What do you think?

And thank you so much for the help!





Return to posts index

demetri tashie
Re: Type 1009 error appears on btns in debug???
on Mar 18, 2009 at 12:34:55 pm

each SWF is it's own independent unit. as long as they all test and work on there own, you can do within it whatever you want : buttons can animate, the whole SWF can animate - whatever you dream up.

here is the code for the main SWF. it should all make sense and be easily adotpable to your situation:


var defaultPhotoRequest:URLRequest=new URLRequest("defaultPhoto.swf");
var photoRequest2:URLRequest=new URLRequest("photoGallery2.swf");
var swfLoader1:Loader=new Loader();
swfLoader1.load(defaultPhotoRequest);
addChild(swfLoader1);

btn1.buttonMode=false;
btn1.alpha=.3;
btn2.buttonMode=true;

btn2.addEventListener(MouseEvent.CLICK, btnClick);

function btnClick(event:Event):void {
removeChild(swfLoader1);
swfLoader1.load(photoRequest2);
addChild(swfLoader1);
btn1.alpha=1;
btn1.buttonMode=true;
btn2.alpha=.3;
btn2.buttonMode=false;
btn1.addEventListener(MouseEvent.CLICK, btnClick2);
btn2.removeEventListener(MouseEvent.CLICK, btnClick);
}


function btnClick2(event:Event):void {
removeChild(swfLoader1);
swfLoader1.load(defaultPhotoRequest);
addChild(swfLoader1);
btn2.alpha=1;
btn2.buttonMode=true;
btn1.alpha=.3;
btn1.buttonMode=false;
btn1.removeEventListener(MouseEvent.CLICK, btnClick2);
btn2.addEventListener(MouseEvent.CLICK, btnClick);
}



then each of the gallery SWFS were made with this code. the 3 buttons are on the main stage:

var photoLoader:Loader = new Loader();
photoLoader.load(new URLRequest('tree4.jpeg'));
addChild(photoLoader);
photoLoader.x=125;
photoLoader.y=75;

button2.addEventListener(MouseEvent.CLICK, pic2);

function pic2(evt:MouseEvent):void{
button2.play();
removeChild(photoLoader);
photoLoader.load(new URLRequest('tree5.jpeg'));
addChild(photoLoader);
}

button1.addEventListener(MouseEvent.CLICK, pic1);

function pic1(evt:MouseEvent):void{
removeChild(photoLoader);
photoLoader.load(new URLRequest('tree6.jpeg'));
addChild(photoLoader);
}

button3.addEventListener(MouseEvent.CLICK, pic3);

function pic3(evt:MouseEvent):void{
removeChild(photoLoader);
photoLoader.load(new URLRequest('tree4.jpeg'));
addChild(photoLoader);
}



if you look back at the example i posted, you will see that i animated button#2 in gallery#2 so you can see that it is possible. the code above reflects that




Return to posts index


Terrence Dunlop
Re: Type 1009 error appears on btns in debug???
on Mar 18, 2009 at 4:03:40 pm

i think I'm beginning to get it: button2 is a movieclip that plays when clicked, as well as loading a new picture into the gallery's loader.

I think I need to know how to animate only the APPEARANCE of the button menus, after which the buttons react with up,over,down and hit states. The problem has been, that a user will click the gallery button from the main page but then the buttons throw the Error#1009 when the user clicks on them after this animation makes them visible.



Return to posts index

Terrence Dunlop
Re: Type 1009 error appears on btns in debug???
on Mar 18, 2009 at 9:01:42 pm

Further research has narrowed it down to a problem with the main timeline - when I put the buttons on the first frame of the mainpage timeline, taking out the opening animations, a simple page test page with an opening navigation bar animation does load in.

So the question now is: how to animate the buttons' appearance, while keeping them where the actionscript can get at them easily without throwing this error!

Or to put it another way - how to get the end frames of these timelines to communicate with each other. Maybe a gotoAndStop function scoped into the gallery page's timeline?

I always thought that as long as your actionscript sat in a keyframe above all other layers on the main timeline, following all the tweening animation of the main timeline, that the movieclips and buttons would be easy for it to find ...





Return to posts index

demetri tashie
Re: Type 1009 error appears on btns in debug???
on Mar 19, 2009 at 3:36:05 am

1) yes- that button is a movie clip, and function attached to it tells it to both play( and thus have it 'animated'), AND to load the new JPG into the galleries image loader

2) my example main timeline ( "PAGE") was a 1 frame SWF. if yours is larger, and it has some animation before it gets to the STOP frame, that is OK too. but your actions should be on the same frame as the STOP action ( i use a new layer). let the buttons associated with these actions also be on the same frame and you will be OK. the buttons can appear before this frame, or be animating however you want, but once they stop on that frame, give them new instance names, and use those names in the script functions.

this means that what comes before, if it needs an instance name, should be given a different instance name, and thought of as a different object, even though they appear to be the same item.

3) let your 'buttons' be buttons, or movieclips. animate any or all states as a button, or make any changes to the movieclip using AS. that is up to you, and will not interfere with the function

4) the 'end frames of the timelines' as you put it - same thing. even though they appear to be one flowing object or paths that then come to a stop. it is the STOP frame that really is your concern. all that comes before it is just pretty filler ( harsh words coming from a designer ! )

i hope that all makes sense and helps. i would suggest you looking through this site, going through some of the great tutorials here. it can really help to get a good feel for this stuff.


Return to posts index


demetri tashie
Re: Type 1009 error appears on btns in debug???
on Mar 19, 2009 at 1:27:43 pm

i don't think i explained that too well - that's the trouble about doing this late at night ....

i modified my gallery 2 to include an 'intro animation' (see previous post for web address)

as long as the button actions are on the same frame as the stop action and the it will work. no need to give different instance names ( that is an old way i used to follow, to keep things straight in my mind...).

here is a screen shot to show you .

note that if i move those button actions to the first frame, instead of the last frame ( the stop frame) , you get the 1009 error message..




Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]