Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 10-24-2004, 11:32 PM   #1
d9085
Registered User
 
Join Date: Mar 2003
Location: Temple City
Posts: 25
Default A Button with dual jobs

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?
d9085 is offline   Reply With Quote
Old 10-25-2004, 01:09 AM   #2
speedlemon
Registered User
 
speedlemon's Avatar
 
Join Date: Jun 2004
Location: U.S.A.
Posts: 108
Default

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.

Code:
onClipEvent(load){
stop();
clicked = false;
}
on(release){
if (clicked == false){
gotoAndStop(2);
clicked = true;
}
if (clicked == true){
gotoAndStop(1);
clicked = false;
}
}
speedlemon is offline   Reply With Quote
Old 10-25-2004, 05:43 PM   #3
d9085
Registered User
 
Join Date: Mar 2003
Location: Temple City
Posts: 25
Default Spoke to soon

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?
d9085 is offline   Reply With Quote
Old 10-25-2004, 06:16 PM   #4
tg
done
 
Join Date: Jun 2001
Location: portland, or
Posts: 8,106
Default

your release should be:

Code:
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:
Code:
on(release){
   gotoAndStop(clicked ? 1 : 2);
   clicked = !clicked;
}
__________________
tg
---
what the hell was i thinking?

Last edited by tg; 10-25-2004 at 06:20 PM.
tg is offline   Reply With Quote
Old 10-25-2004, 09:03 PM   #5
d9085
Registered User
 
Join Date: Mar 2003
Location: Temple City
Posts: 25
Default Tried all of them

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??
d9085 is offline   Reply With Quote
Old 10-25-2004, 09:32 PM   #6
tg
done
 
Join Date: Jun 2001
Location: portland, or
Posts: 8,106
Default

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.
__________________
tg
---
what the hell was i thinking?
tg is offline   Reply With Quote
Old 10-25-2004, 09:45 PM   #7
d9085
Registered User
 
Join Date: Mar 2003
Location: Temple City
Posts: 25
Default

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.
d9085 is offline   Reply With Quote
Old 10-25-2004, 10:08 PM   #8
tg
done
 
Join Date: Jun 2001
Location: portland, or
Posts: 8,106
Default

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:
Code:
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.
Attached Files
File Type: zip f5mcAsButton.zip (3.9 KB, 164 views)
__________________
tg
---
what the hell was i thinking?
tg is offline   Reply With Quote
Old 10-25-2004, 10:44 PM   #9
d9085
Registered User
 
Join Date: Mar 2003
Location: Temple City
Posts: 25
Default

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!
d9085 is offline   Reply With Quote
Old 11-23-2004, 04:48 PM   #10
danthewebguy
Registered User
 
danthewebguy's Avatar
 
Join Date: Aug 2004
Location: Florida
Posts: 59
Send a message via AIM to danthewebguy
Exclamation

what would the release code be in this example if I wanted to moe to a labeled frame on the main timeline?

thanks much!
danthewebguy is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:46 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.