PDA

View Full Version : help about multiple buttons


black_zoro143
10-31-2007, 09:54 AM
i have a function in 1st layer and in 1st frame
in the same frame i have a 2 buttons also
1st button have Instance name which called from another swf.
now i want to apply this function same to these two buttons,
means to say , when these buttons display externally to another swf and when user click on any button the button should work the same.
on click event i want to call the function which is written in 1st frame as i said.
i try this.

1) apply the same instance name.
2) apply different instance name and also call it from different from external swf.

in simple words i want the same functionality with these two buttons if any one of them is click they should work the same.

but its not working

Thank you

Berris
10-31-2007, 12:28 PM
Hi;
What I think you need is a button class (custom component). You'll then be able to create as many instances of this as desired and customise each etc... and have them behave in exactly the same way...

I've attached a basic button component demo.

Hope this helps...

black_zoro143
10-31-2007, 01:29 PM
Thanks for the reply but i think you do not understand what i mean.
here i am telling the the exact and in simple words.
for example:
i have 2 swf files both of them are buttons
i have load 1 button swf in 2nd button swf. but now i want the when i click on second button where i import button1 it work the same as button 1 doing means.
if i apply this code to button1
on(press){
trace("hello");
}

now i load button1 in button2 file. now i have 2 buttons displaying on different positions.
now i want with i click on button2 it hit the same code as button1 doing.

thank you
please help me

Berris
10-31-2007, 03:10 PM
Putting "button1.onPress();" (using correct reference) in the onPress event handler of button2 should do that.

Hope this helps...

black_zoro143
10-31-2007, 09:51 PM
don't have an idea, don't know actionscript :) please help me

Berris
10-31-2007, 10:39 PM
Have a look in the the snippet I sent you before. If say, you were to open up the "compButton" clip and in the first frame in the "onRelease()" event handler write "_root.myButtonClip2.onRelease();" Then when you pressed buttons 1 or 3 they would also automatically press button 2 as well. (This is a bit of a bad example though as I'm not sure what would happen when you press button2. It might send you into an infinite loop!! I haven't tried it. But you get my drift? This is a really static example, obviously it can be made dynamic (with a bit of creativity).

You say you don't know ActionScript... I've always found that one learns best by doing, so doing things like this will get you learning. The help in Flash is quite good; don't be afraid to use it.

black_zoro143
11-01-2007, 08:07 AM
Hello Dear!
thanks alot for your time but the bad news is your comments and help is not really helpful for me here i attach the work i try but its not working.
i am waiting of your good answer thanks

Syllogism
11-01-2007, 09:17 AM
Hi

If I understand what you want, I think I've gotten you a solution. firstly take the code out of the buttons, bad way of coding since your code gets all spread out and hard to find.

second I create a function and in the actions layer of the root timeline I assign that function to the buttons.(will only work if the buttons have instance names btn1, btn2)

then if you want the same function but some aspects different assign sub-values to the button and call then using this.whatever

function traceFunction(){
trace("hello world from "+this.whoAmI);
}
// same function is called by both buttons.
btn1.whoAmI = "button 1"; // create a sub-property of the buttons which can be used when you want invidual values for each button
btn2.whoAmI = "button 2";
btn1.onRelease = traceFunction; // assign the function when you onRelease button
btn2.onRelease = traceFunction; // assign the function when you onRelease button

Antonos
11-01-2007, 09:20 AM
you have to set events in another way
btn1.onRelease = function ()
{
trace("ok");
}
btn2.onRelease = function()
{
_root.btn1.onRelease();
}

Syllogism
11-01-2007, 09:24 AM
what does this dude wanna execute button 2 when you click on button 1? ok...