FORUMS: list search recent posts

need to be pointed in the right direction about buttons

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Peter Kasabian
need to be pointed in the right direction about buttons
on Jul 8, 2009 at 12:33:34 am

Hello,

I'm trying to figure out if this can be done. Lets say you have 3 buttons on a web page. When you hit one of the 3 buttons, text appears and locks on the page. Each button has different texts that appears and locks. No matter what order a person hits a button. The texts for that button appears.


I'm not sure how to do this. I know how to link buttons and send it to different parts of the timeline, just don't know how this would work.



any help to be pointed in the right direction would be great.



Thanks in advance,

Peter


Return to posts index

demetri tashie
Re: need to be pointed in the right direction about buttons
on Jul 13, 2009 at 2:14:47 am

i am answering your question as it is asked, although i suspect there is more too it - like navigation, etc. i'll assume you have that all worked out ?

now-
there are several ways to do this. i would strongly suggest that you look at tutorials on both buttons and using MovieClips as buttons.

take your shape,picture,or whatever you are going to use, and convert it to a MovieClip symbol. give it an instance name( like 'btn1').
double click the symbol to enter its timeline. using the Properties Inspector, give that first frame a frame label
(like "up" ) then add another frame to the timeline,and give that frame a frame label ( like "down" ). add whatever text you like to this "down" frame ( i.e. this will be the frame you see when the MovieClip/button is CLICKED).

so now you have a MovieClip symbol to use for your button,and it has at least, those 2 frames, 'up' which will be the button's normal state, and 'down' which will be it's clicked state.

repeat for as many buttons as you want.

the following code will now make the button clicks work. this is for 2 similar buttons.

the first 2 lines make sure the 2 MovieClip/buttons stay on the first ("up") frame label initially.
the next 2 lines of code add event listeners to the buttons. we save coding steps by giving them the same function.

the function basically says that whichever button is clicked ( the 'event.target'), that if that movieclip is on the 'up' label, then to go to and stop on the 'down' label ( which will reveal the text, or whatever else you add). the next subsequent click on the same button, will see that the clip is stopped on 'down", so it will send it back to 'up' and therefore hide the text/whatever. i added the ability to make the text go away, even though that wasn't part of your question/request.

hope this helps you learn about these processes.


btn1.stop();
btn2.stop();


btn1.addEventListener(MouseEvent.CLICK, clicked);
btn2.addEventListener(MouseEvent.CLICK, clicked);

function clicked(event:MouseEvent):void{
if(event.target.currentLabel=="up"){event.target.gotoAndStop("down")} else
event.target.gotoAndStop("up");
}


this is simplistic, but it should illustrate one way to approach the concept.


Return to posts index

Peter Kasabian
Re: need to be pointed in the right direction about buttons
on Jul 13, 2009 at 2:27:02 pm

Demetri,
Thanks for the input. I'll let you know if I have any problems. I do watch alot of tutorials from total training on flash CS4 and CS3. I haven't done the action script yet though.

thanks again,
Peter


Return to posts index


Peter Kasabian
Re: need to be pointed in the right direction about buttons
on Jul 14, 2009 at 5:01:18 pm

Hi Demetri,
Well, I gave it a shot. I named the button btn1. I have a separate layer for actions. the code is on one frame at the beginning of button 1. I only made one button for now as a test. Here is the code

btn1.stop();

btn1.addEventListener(MouseEvent.CLICK, clicked);

function clicked(event:MouseEvent):void{
if(event.target.currentLabel=="up"){event.target.gotoAndStop("down")} else
event.target.gotoAndStop("up");
}



This is the error message I got:

1084: Syntax error: expecting identifier before if.
1084: Syntax error: expecting rightbrace before leftbrace.


Thanks,
Peter


Return to posts index

demetri tashie
Re: need to be pointed in the right direction about buttons
on Jul 14, 2009 at 5:49:19 pm

hi peter-

i want to make sure that you are first of all using a 'MovieClip symbol" as this button, and not a 'Button Symbol".

then, the code i supplied needs to be on the maintimeline where the "btn1" is, and NOT inside "btn1"s own timeline. there is no code inside the "btn1" timeline, just 2 frames with frame labels; "up" for the normal state, and "down" for the Clicked state, which shows the text ( your text that you want to appear should be placed on this "down" frame also.

if you set it up as such, the code will work correctly. i just retested it with the code for just the one 'button'. you must have some other code that is interfering. you can either comment out all other code, and make sure that this works for you, and then add back code and keep testing until you find the conflict.

but first, make sure this code is on the main timeline, where the actual 'btn1' is, and NOT inside the 'btn1' timeline.
let me know....


Return to posts index

Peter Kasabian
Re: need to be pointed in the right direction about buttons
on Jul 15, 2009 at 6:28:23 pm

Hi Demetri,
I coded it on the main timeline not the button timeline. If It makes a different I'm using Flash CS4 action script 3.0

Just for giggles, I made a new project just with the one button and got the same error message. Here are the steps I did:

(1) frame 1 main timeline - type a text and converted it to a
movie clip and named it "btn1"

(2) double click on the btn1 to get the btn1 timeline.

(3) frame 1 of btn1 timeline, named it "up". Added a frame and
named it "down". then added some text to the "down" frame

(4) Then I hit the arrow to go back to the main timeline. Made a
new layer and put it on top of layer 1. Name the new layer
"actions"

(5) on frmae 1 of main timline went into the action frame pannel.
line (1) btn1.stop();
line (3) btn1.addEventListener(MouseEvent.CLICK, clicked);
line (6) function clicked(event:MouseEvent):void{
line (7) if(event.target.currentLabel=="up"){event.target.gotoAndStop("down")} else

line (8) event.target.gotoAndStop("up");
line (9) }




(6) I hit control enter to get a swf file. the text I made for the
button flashes over and over and got the same error message.

1084: Syntax error: expecting identifier before if.
1084: Syntax error: expecting rightbrace before leftbrace.

I even made sure I got all the current updates

any ideas ?
Peter



Return to posts index


demetri tashie
Re: need to be pointed in the right direction about buttons
on Jul 15, 2009 at 7:39:55 pm

sorry if this is obvious or not, but when you say you named the movieclip " btn1" i hope that ALSO means that you gave it that instance name ( via the Properties Inspector). that could be why the button is flashing over and over.

Actionscript does not recognize the (Library) name of the clip, just the Instance Name given to something on the stage via the Properties Inspector. ( it also recognizes a Linkage name from the Library - but i don't want to confuse you with that now).

make sure the Instance name of btn1 is also btn1, then report back to me.....

BTW i am using CS3 with AS3, but that willnot make a difference for what we are doing...


Return to posts index

demetri tashie
Re: need to be pointed in the right direction about buttons
on Jul 15, 2009 at 8:05:55 pm

here is the fla for this samaple file - why not look at it and see if it makes sense, or if you have any other question, let me know.

good luck !

144_pagebuttons.fla.zip


Return to posts index

Peter Kasabian
Re: need to be pointed in the right direction about buttons
on Jul 16, 2009 at 6:16:33 pm

ok Demetri,

After looking at the file you sent (thank you very much) I made another test project. At first I was getting a error

ReferenceError: Error #1069: Property currentLabel not found on flash.text.TextField and there is no default value.
at Untitled_fla::MainTimeline/clicked()

After checking every detail from yours I noticed my btn1 in the btn1 timeline was set to "dynamic text." Once I set it to "static text", it worked fine.



My original idea was to have the text fade in. I changed the text layer into a movie clip symbol and tweened it but nothing happened. Any chance do you have any ideas ????

Thanks for all the time and patience.

Peter


Return to posts index


demetri tashie
Re: need to be pointed in the right direction about buttons
on Jul 16, 2009 at 8:51:53 pm

Phew - i knew of course there was something not reported getting in the way !
i am glad that you not only now have it working, but i hope that now you have a greater understanding of movieclips, buttons, etc.

to animate the text upon click, you need to change a few things. first, when you go inside the button and see the text, you convert that to a symbol - a graphic symbol should be fine enough. no need to give it an instance name.

then you animate the text as you want it from the 'down' frame labe frame out to however long you want the animation to last. on the last frame of the animation, add a stop(), action.

then on the maintimeline, change the code from gotoAndStop("down") to gotoAndPlay("down").

i am attaching a reworked file showing that. i made a LONG transition/animation which changed position, AND changes its alpha also, so you can understand those, and then create your own transitions/animations etc.
good luck- let me know how it goes....

146_pagebuttons.fla.zip


Return to posts index

Peter Kasabian
Re: need to be pointed in the right direction about buttons
on Jul 21, 2009 at 4:23:16 pm

Hey Demetri,
This is the first time I had a chance to work on this since we last typed.

I found a problem doing this method on my web page I designed, but I figure it out by just trying different things.

When I made a new project and designed it like you said it worked fine. If I tried doing it on my designed webpage it gave me a error and other thing. It wasn't doing what it was suppose too. Anywho. After a bunch of "what if I try this" I figure this out. The button I made was designed in photoshop (just text with some drop shadows and little effects) and imported to flash. Even making the button I imported into movie symbol still wouldn't make it work right. I then just made a quick test text on my designed webpage, then made a symbol out of it and did the coding you taught me and it worked fine. I guess you can’t do this idea if you try to import a button. Or did I do something wrong during the import ????


Hope all is well with you,
Peter


Return to posts index

demetri tashie
Re: need to be pointed in the right direction about buttons
on Jul 21, 2009 at 9:04:33 pm

hi peter,

using imported images made in photoshop makes no difference whatsoever.

i am glad you are experimenting with, ' well, what happens if i try this?' as that is how we learn !

but i still fear that either you are not grasping some fundamental concept of this process, or i am not fully understanding what you are doing.

i remade our ongoing example using an imported photoshop created jpeg as the button graphic, and another photoshop created jpg as the words that are animated in and out via the button click.

i also put it in a HTML page here: ww.demetri-media.com/Sven/button.html

take a look at the html page and the posted fla, and let me know

151_archive.zip


Return to posts index

Cecile de Waal
Re: need to be pointed in the right direction about buttons
on Jul 22, 2009 at 9:21:09 am

Hi
I did almost the same thing, but I have another problem.

Ok, what I did was, I made the word "wash" a movie clip, because I want it to alpha in and out, then I made a button with the same word "wash". The button only has an over state, which is the word "wash" in full colour. Then I dragged the movie clip and button onto scene 1 and put them exactly over each other, so the movie will play but if you go over the word "wash" when the movie is on 0% alpha the word will appear. Then I put a gotoAndStop in, almost the same as your previous post. So if you click on my button it will play a frame in the main timeline which starts a movie clip of pictures.

Here is my problem, when I click on the button I want my movie clip of the word "wash" to still keep on playing(alpha in and out). Everything works except if I click on the button the movie clip of the word "wash" alpha stops playing.


Return to posts index

demetri tashie
Re: need to be pointed in the right direction about buttons
on Jul 22, 2009 at 4:14:25 pm

hi cecile,

first off, i applaud your efforts in thinking out what you want to do, and then figuring out how to get it done. that is what i have always done, and the way i have learned. it just doesn't always lead to the 'best' way of doing things. i say "best' in quotatiaon marks because sometimes 'best' is just a point of view, while other times there are more valid reasons for not doing something one way or another ( especially in coding ! ).

let us also keep in mind that there are often many different ( and equally valid) ways to accomplish the same goal.

that being said, your way is on the one hand fine, becuase it works, and there doesn't seem to be any negative outcome from it ( memory leaks, etc ).

for your problem, i will describe 2 ways of doing it. the first way is probably the most simple. you actually just need to put the movie clip of the animatiaon inside the button symbol in the "up" state of the button. that really solves it - the animation is seen as the normal state. the 'over" state is the static word, and the 'clicked' state is actually returning to the 'up' state.

but you can use this as a good opportunity to learn more about using movieclip symbols as buttons, to further overcome the limitations of button symbols.
some coders and users will tell you you should never use button symbols for buttons, but should only use movie clips as buttons. i believe that button symbols do have their place - they are quick, and easy to use, and require no code on their own. you can even use them to make more complicated animated states, but - they are limited.


let's consider this 'bare-bones' example: your main timeline has 2 frames. the first frame has a movieclip with an instance name of "myButton" that we will use as a 'button'. this movieclip carries over the 2 frames.

the second frame has a movieclip symbol whcih has on its timeline a loop of images .

"myButton" has its own time line, with 2 frame labels, "up" and "over". the up frames are a series of frames with an alpha animation of the word 'wash'. the "over" frame just needs to be a single frame, with a static word 'wash'.

inside "myButton"'s timeline, the last frame in the "up" animation has the code
gotoAndPlay("up"); to keep the animation looping

so the idea is to now code "myButton" so that on MOUSE_OVER, it goes to the static word ( the "over" frame label), and that on a simple MOUSE_OUT, it will then go back to playing the animation loop. a CLICK will do 2 things, it will likewise send "myButton" to loop the "up" section(as a safety- in case you leave the mouse over the symbol), AND it will tell the main timeline to gotoAndStop(2);, so that your image clip will play/loop, AND the "myButton" will keep animating.

I believe that to be what you are trying to accomplish.

here is the code on the the first frame of the main timeline:
stop();


function goesToFrame2(event:MouseEvent):void {
gotoAndStop(2);
myButton.gotoAndPlay("up");
}

function btnFunction(event:MouseEvent):void {
myButton.gotoAndStop("over");
}

function buttonReturnsToNormal(event:MouseEvent):void {
myButton.gotoAndPlay("up");
}

myButton.addEventListener(MouseEvent.CLICK, goesToFrame2);
myButton.addEventListener(MouseEvent.MOUSE_OVER, btnFunction);
myButton.addEventListener(MouseEvent.MOUSE_OUT, buttonReturnsToNormal);


here is the FLA file for you to disect. i hope that helps.

153_untitled2.fla.zip

here is a FLA of the more simple button symbol with the animation on the "up" state:
154_washbutton.fla.zip




Return to posts index

Peter Kasabian
Re: need to be pointed in the right direction about buttons
on Jul 24, 2009 at 5:54:59 pm

Hey Hey,
I knew importing Photoshop file wouldn't be a problem. You know, sometimes wierd stuff happens. I made a new test project and imported my button from photoshop and coded it and it worked just fine.

I feel I have a good understanding of the fundamental concept of flash, just my actionscript is very basic :)

ok, back to this. time for more "what if I do this" for some reason when I try this whole idea on my current website project I get this error

TypeError: Error #1009: Cannot access a property or method of a null object reference.


Trying different things. On my timeline, the button (as a movie clip) first fades in for about 5 seconds. Then I copied the last frame of the movie clip and on the next frame pasted it as a separate symbol to make a button out of it. When I tested it, the text I typed out to show when the button is pressed flashes on and off.

So, instead of copying the last frame of the movie clip. I brought the jpeg in again from the library. set it all up and it works fine now.

I think I got it now .....

Peter


Return to posts index

demetri tashie
Re: need to be pointed in the right direction about buttons
on Jul 25, 2009 at 4:18:19 pm

hi peter-
glad you are figuring it out now. it feels good when it starts making sense !


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]