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.
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
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!
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! ^^
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
this.addEventListener(MouseEvent.MOUSE_DOWN,function(e:MouseEvent){this.startDrag(false,null);});
Hi I was wondering why the above doesnt work? Im trying to drag a sprite around screen.
create a sprite on stage, add instance name box, add code to frame one:
box.addEventListener(MouseEvent.MOUSE_DOWN, startMove);
function startMove(evt:MouseEvent):void {
box.startDrag();
}
box.addEventListener(MouseEvent.MOUSE_UP, stopMove);
function stopMove(e:MouseEvent):void {
box.stopDrag();
}
I think your example doesn't work because of the scope of "this" in the event listener handler.
If you remove this.; it will work. It's a scope issue since you use an anonymous function.
You could use the currentTarget of the event, this allows you to make other boxes draggable too, if you add the same listeners.
Note: It is hard to remove an anonymous function as event listener and could cause memory leaks, so the best way is to use a reference to a named function:
box.addEventListener(MouseEvent.MOUSE_DOWN, handleMouseEvent);
box.addEventListener(MouseEvent.MOUSE_UP, handleMouseEvent);
function handleMouseEvent(event:MouseEvent):void
{
switch(event.type)
{
case MouseEvent.MOUSE_DOWN:
{
DisplayObject(event.currentTarget).startDrag();
break;
}
case MouseEvent.MOUSE_UP:
{
DisplayObject(event.currentTarget).stopDrag();
break;
}
}
}