I'm new to AS3, and I keep getting Error #1009 when I try to add a button. From some reading I did I gather it is when I reference something I think exists but that really doesn't, except I have added a correct instance_name, and this did not happen for any of my other buttons.
Below is my code:
stop();
//buttons
Erhu_btn.addEventListener(MouseEvent.MOUSE_DOWN, Erhu_func);
Flute_btn.addEventListener(MouseEvent.MOUSE_DOWN, Flute_func);
Guzheng_btn.addEventListener(MouseEvent.MOUSE_DOWN, Guzheng_func);
Ruan_btn.addEventListener(MouseEvent.MOUSE_DOWN, Ruan_func);
Yangqin_btn.addEventListener(MouseEvent.MOUSE_DOWN, Yangqin_func);
Compose_btn.addEventListener(MouseEvent.MOUSE_DOWN, Compose_func);
Intro_btn.addEventListener(MouseEvent.MOUSE_DOWN, Intro_func);
//function definitions
function Erhu_func(event:MouseEvent):void {
gotoAndStop("Erhu");
}
function Flute_func(event:MouseEvent):void {
gotoAndStop("Flute");
}
function Guzheng_func(event:MouseEvent):void {
gotoAndStop("Guzheng");
}
function Ruan_func(event:MouseEvent):void {
gotoAndStop("Ruan");
}
function Yangqin_func(event:MouseEvent):void {
gotoAndStop("Yangqin");
}
function Compose_func(event:MouseEvent):void {
gotoAndStop("Compose");
}
function Intro_func(event:MouseEvent):void {
gotoAndStop("Intro");
}
All the buttons work except for the Intro_btn. I know it's probably a really simple mistake, but I can't figure it out, and I would really appreciate any light you could shed on my problem!
Related
I'm trying to create something similar to Impossible Quiz Question 5 (1st quiz). However the hitTestPoint appears to be not reading. I'm not exactly sure where my error is.
Here is my full line of code.
stop();
blueTarget.addEventListener(MouseEvent.MOUSE_OVER, mousehandler2);
function mousehandler2(e:MouseEvent):void {
if (blueTarget.hitTestPoint(mouseX,mouseY,true)) {
removeEventListener(MouseEvent.MOUSE_OVER, mousehandler2);
gotoAndStop("lose");
}
}
nexttButton.addEventListener(MouseEvent.MOUSE_DOWN, mousehandler3);
function mousehandler3(e:MouseEvent):void {
removeEventListener(MouseEvent.MOUSE_DOWN, mousehandler3);
MovieClip(root).nextFrame();
}
Thanks for the help!
Do you want the player to lose if he passes the mouse over the blueTarget? If so, you can remove your if statement because the mouse over event is already added to the blueTarget
So i been trying to create to create a flash video gallery for my website but im getting an error on it even though the code should be correct
Below is the code i came up with
stop();
one.add Eventlistener(MouseEvent.CLICK,vid1);
two.add Eventlistener(MouseEvent.CLICK,vid2);
three.add Eventlistener(MouseEvent.CLICK,vid3);
four.add Eventlistener(MouseEvent.CLICK,vid4);
five.add Eventlistener(MouseEvent.CLICK,vid5);
function vid1(event:MouseEvent):void
{
vidPlayer.source ="flv/01.flv"
}
function vid2(event:MouseEvent):void
{
vidPlayer.source ="flv/02.flv"
}
function vid3(event:MouseEvent):void
{
vidPlayer.source ="flv/03.flv"
}
`enter code here`function vid4(event:MouseEvent):void
{
vidPlayer.source ="flv/04.flv"
}
function vid5(event:MouseEvent):void
{
vidPlayer.source ="flv/05.flv"
}
vidPlayer.playButton = player
vidPlayer.pauseButton = pauser
Does anyone have any idea on whats wrong with it ?
addEventlistener is a function, which will register an event listener object, and the name of a function should never contain spaces which is your error, so you should write :
one.addEventlistener(MouseEvent.CLICK,vid1);
two.addEventlistener(MouseEvent.CLICK,vid2);
three.addEventlistener(MouseEvent.CLICK,vid3);
four.addEventlistener(MouseEvent.CLICK,vid4);
five.addEventlistener(MouseEvent.CLICK,vid5);
Hope that can help.
I have a question. I'm beginner so...
I'm creating website on flash and i have 5 pages and 5 buttons(menu buttons) and I need to use menu so I wrote this code but aobe flash writes error 1120, whats a problem?;s
thisi is code
{stop();
function projectsButton_clicked (e:MouseEvent) :void {
gotoAndStop("projects");
}
function galleryButton_clicked (e:MouseEvent) :void {
gotoAndStop("gallery");
}
function videosButton_clicked (e:MouseEvent) :void {
gotoAndStop("videos");
}
function backstageButton_clicked (e:MouseEvent) :void {
gotoAndStop("backstage");
}
function pricelistButton_clicked (e:MouseEvent) :void {
gotoAndStop("pricelist");
}
function contactButton_clicked (e:MouseEvent) :void {
gotoAndStop("contact");
}
projectsButton.addEventListener(MouseEvent.CLICK, projectsButton_clicked);
galleryButton.addEventListener(MouseEvent.CLICK, galleryButton_clicked);
videosButton.addEventListener(MouseEvent.CLICK, videosButton_clicked);
backstageButton.addEventListener(MouseEvent.CLICK, backstageButton_clicked);
pricelistButton.addEventListener(MouseEvent.CLICK, pricelistButton_clicked);
contactButton.addEventListener(MouseEvent.CLICK, contactButton_clicked);
}
Well, there are a couple of things wrong in your code:
The useless braces at the beginning and end of the program { }, but I don't think that affects much.
If you're using scenes, this is how gotoAndStop should be used: gotoAndStop(frame, "Scene name"); , unless they're all frames of a movieclip, in that case you should just use the frame number. Here you go: http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001310.html
Those were just notes since those might cause errors later, the most likely cause of your error is that one or a couple of buttons mentioned in the code (projectsButton, galleryButton, videosButton, etc...) don't actually exist, they either aren't on the stage or when you were naming them on the stage you misspelled one/some of them. I think you should double check all their instance names.
That's all I can think of, best of luck with your website! ^^
Why does this not work (doesn't go to frame 15)
navLeft.addEventListener(MouseEvent.CLICK, goLeft2);
function goLeft2(e:MouseEvent):void
{
TweenLite.to(page1ani2, 1, {x:880, y:215, onComplete: goLeft22});
}
function goLeft22(e:MouseEvent):void
{
gotoAndStop(15);
}
yet this does!
navLeft.addEventListener(MouseEvent.CLICK, goLeft22);
function goLeft22(e:MouseEvent):void
{
gotoAndStop(15);
}
It doesn't like to do a tween before going to the gotoAndstop() function, why is this?
any help appreciated.
Ian
This does not work because you have goLeft22() with an expected argument of type MouseEvent. Try changing it to:
function goLeft22(e:MouseEvent=null):void
{
gotoAndStop(15);
}
This makes the argument optional.
I want to create a function that only allows the second frame of a movie clip to allow navigation of SWF. The "2button" is the original movie-clip while the "unlock2" is a different movie-clip on the second frame of "2button"
I tried:
//test
public function open(){
2button.unlock2.addEventListener(MouseEvent.CLICK,clickjump2);
function clickjump2(event:MouseEvent) {
gotoAndStop("play2");
}
}
Any suggestions or improvements to this would be greatly appreciated :D!
try this:
function open():void
{
2button.unlock2.addEventListener(MouseEvent.CLICK,clickjump2);
}
function clickjump2(event:MouseEvent):void
{
//check if 2button is at frame 2
if (2button.currentframe==2)
{
gotoAndStop("play2");
}
}
ps: as Versper pointed out, dont start names with numbers