button action

  • DurianFruit
  • Novice
  • Novice
  • DurianFruit
  • Posts: 33
  • Loc: Toronto, ON

Post 3+ Months Ago

I'm new at flash. I have created a button from a rectangle and I want this button to jump to a page whenever its clicked on. I created a new layer with no components or anything related to this layer. I only added a action script at the beginning to this layer and called the layer "AllActions" based on the 'Components" tutorial that comes with Flash MX. here is the code I added to this layer.

Code: [ Select ]
function onClick(btn) {
    if (btn == green_btn) {
        gotoAndStop("pg1");
    }
}
function onClick(btn) {
    if (btn == red_btn) {
        gotoAndStop("pg2");
    }
}
function onClick(btn) {
    if (btn == orange_btn) {
        gotoAndStop("pg3");
    }
}
  1. function onClick(btn) {
  2.     if (btn == green_btn) {
  3.         gotoAndStop("pg1");
  4.     }
  5. }
  6. function onClick(btn) {
  7.     if (btn == red_btn) {
  8.         gotoAndStop("pg2");
  9.     }
  10. }
  11. function onClick(btn) {
  12.     if (btn == orange_btn) {
  13.         gotoAndStop("pg3");
  14.     }
  15. }


The idea is when you go to http://cliff.smart-host.us/ you would see an intro and then a 'color selection' page fades in. After you select one of the 3 colors a circle with the color you selected will appear under the 'your current color' title.

Please help me out. Thank you for you time.
  • suzie
  • Guru
  • Guru
  • User avatar
  • Posts: 1134
  • Loc: England

Post 3+ Months Ago

Buttons will do whateva you tell them to do..
You told it to stop in all the scripts--it stopped.!
I don't see ..gotosceneandplay..gotoframe(1)and play etc, so it won't play for you..add another event.
Unless another member has a solution to your problem...
:)
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

The function is being overwritten, this,
Code: [ Select ]
function onClick(btn) {
  if (btn == green_btn) {
   gotoAndStop("pg1");
  }
}
function onClick(btn) {
  if (btn == red_btn) {
   gotoAndStop("pg2");
  }
}
function onClick(btn) {
  if (btn == orange_btn) {
   gotoAndStop("pg3");
  }
}
  1. function onClick(btn) {
  2.   if (btn == green_btn) {
  3.    gotoAndStop("pg1");
  4.   }
  5. }
  6. function onClick(btn) {
  7.   if (btn == red_btn) {
  8.    gotoAndStop("pg2");
  9.   }
  10. }
  11. function onClick(btn) {
  12.   if (btn == orange_btn) {
  13.    gotoAndStop("pg3");
  14.   }
  15. }

Needs to be,
Code: [ Select ]
function onClick(btn) {
  if (btn == green_btn) {
   gotoAndStop("pg1");
  }
  else if (btn == red_btn) {
   gotoAndStop("pg2");
  }
  else {
   gotoAndStop("pg3");
  }
}
  1. function onClick(btn) {
  2.   if (btn == green_btn) {
  3.    gotoAndStop("pg1");
  4.   }
  5.   else if (btn == red_btn) {
  6.    gotoAndStop("pg2");
  7.   }
  8.   else {
  9.    gotoAndStop("pg3");
  10.   }
  11. }

On the buttons themselves you would call this function like so,
Code: [ Select ]
on(press){
   _root.onClick(this._name);
}
  1. on(press){
  2.    _root.onClick(this._name);
  3. }


You can save a headache by placing the gotoAndStop actions right on the buttons themselves.
Code: [ Select ]
on(press){
   this._parent.gotoAndStop("pg1");
}
  1. on(press){
  2.    this._parent.gotoAndStop("pg1");
  3. }

Of course changing the "pg1" for each button.
  • DurianFruit
  • Novice
  • Novice
  • DurianFruit
  • Posts: 33
  • Loc: Toronto, ON

Post 3+ Months Ago

Thank you guys for your help. Sorry for the late replies I was busy with exams now that I'm done my exams I will take your advices and try to make this thing work.

Durian.
  • DurianFruit
  • Novice
  • Novice
  • DurianFruit
  • Posts: 33
  • Loc: Toronto, ON

Post 3+ Months Ago

It works!!!! ^_^

http://www.cliffwang.com

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 5 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.