Skip to main content
Participant
March 4, 2009
Answered

NEWBIE HELP - Button Scripting

  • March 4, 2009
  • 3 replies
  • 414 views
I'm completely new to this, so no need to tell me how stupid the coding is, and please keep the answers simple, hehe.. Thanks in advance to everyone who can help me out here! :)

Situation:
I have a menu with four moving (classic tweened) buttons, all coded the same.
Two of them works, but two of them won't play/move. Everything is done exactly the same, instance-names are correct, and so on - but the debug'er says there's something wrong with the third button (line 10, marked with a *) - and gives me this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at 5_fla::MainTimeline/frame1()


And if there's a better way of doing this (which I'm sure there is plenty of), I'd love to know how you'd do it :)
All help is appreciated!

Here's my first attempt at flash coding:
____________________________________________________
This topic has been closed for replies.
Correct answer clbeech
you're code looks just fine - good job :) i see no particular errors here other than that I might go with MouseEvent.CLICK - but that is an arbitrary choice and what have is just fine.

a 1009 error means that 'something' that you are targeting is not instantiated (present) on the timeline at the time that the code is executed. this could mean that there is an instance name issue (you say not - but it never hurts to double check... well maybe a little lol) it also may be possible that one of the buttons (third) is on 'another frame' perhaps in the near future? you can only assign the event listeners to items that are available at the time, so you'd have to wait until that point.

again though, everyone needs to start somewhere - you're code isn't stupid and you've done a fine job.

3 replies

Participant
March 4, 2009
Thanks alot you guys! You just made my day :)

There was a problem with the third button timeline, and the forth instance name was missing one character in the scripted frame. Silly me!
That's what you get when it's 5 am, and you've been sitting for 10 straight hours just falling in love with Flash, and also hating yourself for not getting things right faster, hehe.

Thanks again for your time and minds you guys..

Edit: I could only mark one of the posts as 'the answer', but they we're both right ofcourse.. and I was sooo wrong, hehe :P
Participant
March 4, 2009
can't see why you'd get the null error, you say your instance names are correct but i'd check for typos, case issues etc.

you could tidy up your code by having one method

function doGoFrame(event:Event) {
switch (event.target.name) {
case "firstbutton" :
gotoAndPlay(1);
break;
case "secondbutton":
gotoAndPlay(2);
break;
//etc
}

also don't refer to your frames by number but rather by frameLabel. assuming you suddenly need to add frames somewhere, then you have to go change everything whereas if you're refering to the label you're cool.

clbeech
clbeechCorrect answer
Inspiring
March 4, 2009
you're code looks just fine - good job :) i see no particular errors here other than that I might go with MouseEvent.CLICK - but that is an arbitrary choice and what have is just fine.

a 1009 error means that 'something' that you are targeting is not instantiated (present) on the timeline at the time that the code is executed. this could mean that there is an instance name issue (you say not - but it never hurts to double check... well maybe a little lol) it also may be possible that one of the buttons (third) is on 'another frame' perhaps in the near future? you can only assign the event listeners to items that are available at the time, so you'd have to wait until that point.

again though, everyone needs to start somewhere - you're code isn't stupid and you've done a fine job.