Flash var/Functions
- Started
- Last post
- 18 Responses
- springbok
Does anyone know if there is a way of doing this or if its even possible?
VAR DECLARATION
var currentSelection:String = "";ATTACHED TO A BUTTON
_root.currentSelection = "AboutUsL2Selected();";USAGE
_root.currentSelection;I have created some functions that I want to call depending on which button has been pressed. Is there a way of calling a function using a variable as shown above?
- springbok0
anyone help?
- UndoUndo0
I dont quite understand. to call a func from a button you need something like this.
_global.myfunction = function(){
// do something
}// _global makes it available anywhere in yr swf
_root.mybutton.onPress = function(){
// call my functionmyfunction();
}
- joyride0
put a parameter in the function so you know which button is pressed
function myButton (whatsPressed : String){
do something;
}Then in the function you can us if statements depending on whatsPressed...
make sense?I think thats what your trying to do?
- springbok0
this.mc_NAVL1.mc_btn_about_us.on... = function() {
MakeLineAppearL1();
_root.AboutusPressed();
_root.currentSelection = "AboutUsL2Selected();"
};So if this is my funtion for my BTN how would I code it?
This is the Function
function AboutUsL2Selected() {
_root.mc_NAVL1.mc_btn_home.targe...
_root.mc_NAVL1.mc_btn_about_us.t...
_root.mc_NAVL1.mc_btn_portfolio...
_root.mc_NAVL1.mc_btn_news_featu...
_root.mc_NAVL1.mc_btn_contact.ta...
}Would I do something like this?
function AboutUsL2Selected(whatsPressed : String) {
and how would I then call this?
Thanks for the help
- springbok0
Joyride2 any chance you could help
- unformatted0
if your function is on the root:
_root.[ _root.currentSelection ]();
or you could do this:
var currSelection:Function
and just pass the function name.
- joyride0
sorry man, had a meeting. I'll take a look now and see what your samples doing
- springbok0
cant seem to get this working unformatted, I have done this
var currSelection:Function;
_root.currSelection();
_root.currSelection = "AboutUsL2Selected();";
Is this correct?
- springbok0
cheers joyride
- springbok0
any Joy!
- trintaetres0
Hi Springbok!
You want a function to be called every time that variable changes?
You will have to use a listener... to listen when the variable changes an call the function
- tomkat0
like before mentioned do so:
function thisIncludesAllStuff(num)
{
// use switch statement in here
}use of switch:
http://www.kirupa.com/developer/…
;)
- springbok0
cheers guys ill give them a go
- joyride0
sorry man, seems to be a day of meetings. I'll look into it later tonight... sorry bro
- springbok0
if you could joyride that would be great
- unformatted0
i posted 2 options before, but try this:
_root.[ _root.currentSelection ]();
- joyride0
OK, I think i understand what your trying to do. But still not totally sure:
Button On Release Code:
this.mc_NAVL1.mc_btn _about_us. onRelease = function ( ) {
MakeLineAppearL1 ("AboutUs Pressed");
}Then on the timeline where MakeLineAppearL1 exists (you might need to set the path to this function)
function MakeLineAppearL1 ( WhichPress:Str ing) {
doWhatever for all buttons;if (WhichPress = = "AboutUs Pressed") {
do something
}
}in MakeLineAppearL1 this can be a series of if statement looking for a match or you can use the case statements either way, you're looking for the parameter set when you press the button.
That work for ya?
- trintaetres0
Try this:
Create 2 buttons on stage, then instancename them "btn_01" and "btn_02" ,then paste the code at the first frame:var btnPressed:String;
btn_01.onRelease = function(){
btnPressed = "btn_01";
executer();
}btn_02.onRelease = function(){
btnPressed = "btn_02";
executer();
}executer();
function executer(){
switch (btnPressed) {
case "btn_01":
function01();
break;
case "btn_02":
function02();
break;
default: function01();
}
}function function01(){
trace("function01 executed")
};function function02(){
trace("function02 executed")
};tell me if it helps you!