Actionscript 3.0 Buttons Aren't working but some are - actionscript-3

Most of my buttons Aren't working but some are working. I'm not exactly sure why either.
[This is what most of my frames look like as well][2]
stop();
main_btn.addEventListener(MouseEvent.CLICK, mainClick);
function mainClick(event:MouseEvent):void{
gotoAndStop (1);
mainX_btn.addEventListener(MouseEvent.CLICK, mainClick);
}
fact1_btn.addEventListener(MouseEvent.CLICK, fact1Click);
function fact1Click(event:MouseEvent):void{
gotoAndStop (2);
fact1_btn.addEventListener(MouseEvent.CLICK, fact1Click);
}
fact2_btn.addEventListener(MouseEvent.CLICK, fact2Click);
function fact2Click(event:MouseEvent):void{
gotoAndStop (3);
fact2X_btn.addEventListener(MouseEvent.CLICK, fact2Click);
}
fact3_btn.addEventListener(MouseEvent.CLICK, fact3Click);
function fact3Click(event:MouseEvent):void{
gotoAndStop (4);
fact3_btn.addEventListener(MouseEvent.CLICK, fact3Click);
}

Is it what you mean?
main_btn.addEventListener(MouseEvent.CLICK, mainClick);
mainX_btn.addEventListener(MouseEvent.CLICK, mainClick);
function mainClick(event:MouseEvent):void{
gotoAndStop (1);
}
fact1_btn.addEventListener(MouseEvent.CLICK, fact1Click);
fact1X_btn.addEventListener(MouseEvent.CLICK, fact1Click);
function fact1Click(event:MouseEvent):void{
gotoAndStop (2);
}
fact2_btn.addEventListener(MouseEvent.CLICK, fact2Click);
fact2X_btn.addEventListener(MouseEvent.CLICK, fact2Click);
function fact2Click(event:MouseEvent):void{
gotoAndStop (3);
}
fact3_btn.addEventListener(MouseEvent.CLICK, fact3Click);
fact3X_btn.addEventListener(MouseEvent.CLICK, fact3Click);
function fact3Click(event:MouseEvent):void{
gotoAndStop (4);
}

Related

encounter in animation a mouse over and mouse out in nested timeline

problem when i mouse over or mouse out using actionscript 3 to my button it keeps on repeating and not finishing the animation or worse the animation or the object is not showing. ive put on labels for guide to where the animation is if you mouse_over the button or mouse out, ive also put a stop action
here is my code
stop();
import flash.events.Event;
btn1_mc.addEventListener(MouseEvent.MOUSE_OVER, casinoHome);
function casinoHome (e:MouseEvent):void{
MovieClip(this.root).btn1_mc.gotoAndPlay("rover");
MovieClip(this.root).outline1_mc.gotoAndPlay("roveroutline");
}
btn1_mc.addEventListener(MouseEvent.MOUSE_OUT, casinoHome2);
function casinoHome2 (e:MouseEvent):void{
MovieClip(this.root).btn1_mc.gotoAndPlay("mouseout");
MovieClip(this.root).outline1_mc.gotoAndPlay("mouseoutine");
}
btn2_mc.addEventListener(MouseEvent.MOUSE_OVER, sportsHome);
function sportsHome (e:MouseEvent):void{
MovieClip(this.root).btn2_mc.gotoAndPlay("rover2");
}
btn2_mc.addEventListener(MouseEvent.MOUSE_OUT, sportsHome2);
function sportsHome2 (e:MouseEvent):void{
MovieClip(this.root).btn2_mc.gotoAndPlay("mouseout2");
}
btn3_mc.addEventListener(MouseEvent.MOUSE_OVER, slotHome);
function slotHome (e:MouseEvent):void{
MovieClip(this.root).btn3_mc.gotoAndPlay("rover3");
}
btn3_mc.addEventListener(MouseEvent.MOUSE_OUT, slotHome2);
function slotHome2 (e:MouseEvent):void{
MovieClip(this.root).btn3_mc.gotoAndPlay("mouseout3");
}
check if you have put a stop(); action at the end of each animation.
example:
btn1_mc:
outline1_mc:

ActionScript call a function within another function

I have a function (gofromTheFuture) that controls tweening objects that is then linked to various buttons, however I also want it to be called from this function below, but flash gives me this error:
Incorrect number of arguments. Expected 1.
function exitHandler(event:Event):void
{
event.preventDefault();
gofromTheFuture();
}
function gofromTheFuture(evt:Event):void{
myTimeline2.insertMultiple( TweenMax.allTo([TheFutureArtwork, pausebutton, playbutton, Verse, Chorus, Verseto1, Verseto2, Chorusto1, Chorusto2, rewind, fastforward, progressline, progressbar, TheFutureComments],
0.25, {x:"450", autoAlpha:0, onComplete:exitAnimation}) );
}
function exitAnimation():void {
trace("Return to main menu.");
gotoAndStop(1, "Menu");
}
How do I call this gofromTheFuture from within this function?
Thanks
Try change gofromTheFuture() to:
function gofromTheFuture(evt:Event = null):void

MovieClip not reacting how I intended on rollover

I thought I had it but I am still not able to get my movieClip to play(). I am getting the trace that its making it into the "updateBomb" function on rollover but my currentBomb is not going to frame 2 and playing. Any ideas why this is happening? Could it be because my movieclips are in a container MC?
function getStarted(event:MouseEvent){
startClip.removeEventListener(MouseEvent.ROLL_OVER, getStarted);
for (var i:int = 1; i < 11; i++) {
var currentBomb:MovieClip = bombClip["bomb_" + i];
trace(currentBomb);
currentBomb.addEventListener(MouseEvent.ROLL_OVER, function (evt:MouseEvent):void { updateBomb(currentBomb); });
}
bombClip.play();
}
function updateBomb(currentBomb:MovieClip):void {
trace("in update bomb");
trace(currentBomb);
currentBomb.gotoAndPlay(2);
}
I added a trace currentBomb in updateBomb and this is what I get
[object bombNum1_5]
in update bomb
[object bombNum1_5]
in update bomb
[object bombNum1_5]
in update bomb
[object bombNum1_5]
in update bomb
[object bombNum1_5]
in update bomb
[object bombNum1_5]
When I rollover different bombs. Do I need to reference the bombs by name?
You are adding an event listener using an anonymous function, creating a closure by storing the currentBomb in the mouse roll over handler.
However, that currentBomb variable is being changed in the loop. And each anonymous function has a reference to it. So when you mouse over each movie clip, they all point to the same bomb (the last one in the loop).
Instead of using the anonymous function, just add an event listener like below. The event handler can rely on the fact that the event came from a MovieClip and call it's gotoAndPlay() method:
// inside the for loop...
currentBomb.addEventListener(MouseEvent.ROLL_OVER, updateBomb);
// roll over event handler
function updateBomb(event:MouseEvent):void
{
var currentBomb:MovieClip = event.target as MovieClip;
if (currentBomb) // is null if above line fails
currentBomb.gotoAndPlay(2);
}

AS3 When symbol is in a certain position

I'm using Flash Professional CS5.5 and I need to make an app where there is a ball (symbol) that moves using the accelerometer and I want that, when the ball A coordinates reach this coordinates B I go to frame 2 (gotoAndPlay(2)). I have to find the ball coord first, right?
How do I make this?
Here is the code I've now
c_ball.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);
function fl_ClickToDrag(event:MouseEvent):void{
c_ball.startDrag();}
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
function fl_ReleaseToDrop(event:MouseEvent):void{
c_ball.stopDrag();}
would it work if, after retriving the coordinates?
function f_level (e) if (c_ball.x==100 && c_ball.y==100) {
gotoAndStop(2);}
Use Collision detection creating a targetarea and test it with your ball - object if wanted onEnterframe or when every you thing its time:
private function test():void{
if( ball.hitTestObject(testarea) ){
// here goes next frame command ;)
}
}
I would add an enter frame event listener, and check the coordinates of c_ball there.
stage.addEventListener(Event.ENTER_FRAME, siteLoop);
public function siteLoop(event:Event)
{
if ((c_ball.x > 99.9) && (c_ball.y > 99.9)){
gotoAndStop(2);
}
}

Is there a way to listen for the completion of a MovieClip playing?

I want to execute a function upon completion of a MovieClip's animation. That is, I would command it to play() or gotoAndPlay(). I don't know of any listener that I can attach to the MovieClip with the "addEventListener()" command. Have any idea I can do?
You can use the addFrameScript method, as shown in this post to dispatch a custom event when the last frame is reached.
stage.addEventListener(Event.ENTER_FRAME, onCheckAnimationComplete)
function onCheckAnimationComplete(e:Event)
{
if(animation.currentFrame==animation.totalFrames)
{
//TODO call a function
}
}