View Full Version : A Button with dual jobs
d9085
10-25-2004, 12:32 AM
I am making a criss cross word puzzle. Of course the letters run vertical as well as horizontal. If the user clicked once on their intended letter, it would turn blue (or whatever color I choose). Then they'd move to the next letter. If they found out the letter(s) they clicked on were not the correct ones or the ones they wanted, they would click the letter again and it would return to it's natural or starting color.
My theory was to make each letter a button. And in the AS write that the first click turns the letter blue (or whatever color I want) and the next click turns it back to the original color.
I started by making a letter into a button.
I added this AS:
on (release) {
}
Where do I go from here? :confused:
speedlemon
10-25-2004, 02:09 AM
umm ok. im sure there are tons of ways of to do this. heres one way. make it a movie clip instead. make it 2 frames long. one with the original color, the second frame with blue(or w/e color you choose...). now insert this code into the movie clip.
onClipEvent(load){
stop();
clicked = false;
}
on(release){
if (clicked == false){
gotoAndStop(2);
clicked = true;
}
if (clicked == true){
gotoAndStop(1);
clicked = false;
}
}
d9085
10-25-2004, 06:43 PM
Sorry I didn't tell you I am using Flash 5. I don't know if it makes a difference.
I made a MC two frames long with a Black "A" in frame 1 and a Blue "A" in frame 2. I dragged the MC onto the canvas from the library. I clicked it and then opened the Actions window. I tried to paste:
Code:
onClipEvent(load){
stop();
clicked = false;
}
on(release){
if (clicked == false){
gotoAndStop(2);
clicked = true;
}
if (clicked == true){
gotoAndStop(1);
clicked = false;
}
}
But a message came up stating:
The Actions on the clipboard contain errors. Actions with errors cannot
be pasted into normal mode.
The Output window states this:
Clipboard Actions: Line 1: ';' expected
Code:
If I change to Expert mode I get this output after I press "F12"
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 1: ';' expected
Code:
AND
the MC changes rapidly from Black to Blue.
Any suggestions?
your release should be:
on(release){
if (clicked == false){
gotoAndStop(2);
clicked = true;
}else{
gotoAndStop(1);
clicked = false;
}
}
the other way, if the button is released and 'clicked==false', then the false statement is executed. clicked is changed to true, it exits the if statement and imediately executes the clicked == true statement
so, you need an else instead of 2 separate ifs.
another way to do the same thing is:
on(release){
gotoAndStop(clicked ? 1 : 2);
clicked = !clicked;
}
d9085
10-25-2004, 10:03 PM
Using Flash 5
Starting on the 1st frame of the canvas I make an "A"
"A" is highlited. I click "F8"
Choose "Movie"
Name it "A"
Double click on "A" MC in Library
I have a black "A" in frame 1 and make a red "A" in frame 2
Back on the canvas
Click on the MC and have pasted code from Speedlemon:
onClipEvent(load){
stop();
clicked = false;
}
on(release){
if (clicked == false){
gotoAndStop(2);
clicked = true;
}
if (clicked == true){
gotoAndStop(1);
clicked = false;
}
}
Results from Output:
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 5: Mouse events are permitted only for button instances
on(release){
Pasted code from tg
onClipEvent(load){
stop();
clicked = false;
}
on(release){
if (clicked == false){
gotoAndStop(2);
clicked = true;
}else{
gotoAndStop(1);
clicked = false;
}
}
Results from Output:
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 5: Mouse events are permitted only for button instances
on(release){
Pasted other code from tg
onClipEvent(load){
stop();
clicked = false;
}
on(release){
gotoAndStop(clicked ? 1 : 2);
clicked = !clicked;
}
Results from Output:
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 5: Mouse events are permitted only for button instances
on(release){
I certainly don't know.
What's wrong??
nope.... needs to be a button not an mc.... hold on a bit, and i will see if i can dig up some old source code i did in f5.
d9085
10-25-2004, 10:45 PM
How can you have two frames on a Button? There is only UP - OVER - DOWN - HIT.
I will wait for you to see if you find something.
1st. make sure the code is on the mc (not inside the mc).
use hittest to make sure that the mouse is hitting the mc.
since your not useing an actual button object, you cant use 'release' thats a button method.
so heres the code that works:
onClipEvent (load) {
stop();
clicked = false;
}
//this works
//onClipEvent(mouseUp){
// if(this.hitTest(_root._xmouse,_root._ymouse,false) ){
// if (clicked == false){
// gotoAndStop(2);
// clicked = true;
// }else{
// gotoAndStop(1);
// clicked = false;
// }
// }
//}
//so does this... (maybe not in 5).
onClipEvent (mouseUp) {
if (this.hitTest(_root._xmouse, _root._ymouse, false)) {
gotoAndStop(clicked ? 1 : 2);
clicked = !clicked;
}
}
both mouse up methods work, i just thought i would do both.
heres the fla... it was created with mx, but published for 5, so hopefully you will be able to open it.
d9085
10-25-2004, 11:44 PM
Yeh baby! That's what I'm talking about.
I tried the ZIP file but it's in an 'unexpected format' for Flash 5.
Sure am greatful for all your, and everyone elses input.
You guys rock!
danthewebguy
11-23-2004, 05:48 PM
what would the release code be in this example if I wanted to moe to a labeled frame on the main timeline?
thanks much! :D
Gibberish
11-23-2004, 06:12 PM
change the gotoAndStop()'s
insstead of gotoAndStop(2); put gotoAndStop('myLabel');
danthewebguy
11-23-2004, 06:28 PM
guess I'm getting nuts here because I have a different situation. I have the following code on my mc to show a rollover animation:
//////////////////////////////////////////////////////////
on (rollOver) {
this.btn_about.gotoAndPlay("mouseover");
setProperty(this.btn_about, _x, 25);
setProperty(this.btn_about, _y, 29);
}
on (rollOut) {
this.btn_about.gotoAndPlay("mouseout");
}
////////////////////////////////////////////////////////
Then, I have a "hit area" only placed above the text of my navigation with the that acts as the button . . .
danthewebguy
11-23-2004, 06:35 PM
here's my fla if you're interested . . .
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.