View Full Version : Discovering the pressed button and associatin a variable with an string
Moralez
09-25-2003, 10:56 AM
I just need to know how can I find witch button the user pressed and how to associate variables with strings.
I wish to do something like this:
If PressedButton = "Button"+N
Then GetUrl (www.blabla.com/pageN.htm)
How to do so?
Thanks in advance...
dzy2566
09-25-2003, 11:03 AM
On each button, you can set a variable.
myButton1.onRelease = function(){
_root.buttonPressed = 1;
}
myButton2.onRelease = function(){
_root.buttonPressed = 2;
}
// .... and so on
// use this variable wherever you like
// in a function
function myGoto(where){
if(where == 1){
// do this
}else if (where == 2){
// do something else
}
}
Keep in mind that if it suits whatever you're doing, you can put the getURL right on the button.
Moralez
09-25-2003, 12:22 PM
Thank you for the help but it's not exactly what I need.
The thing is I created a Script that by giving X,Y coordenates of an rectangle/square and the number of buttons that the "user" wishes to insert in that same space the Scrip will Generate several different buttons with adjusted X,Y positions, height, weight and the correspondent number.
As you can see the ideia is to create a self-assembly script for a IndexBar (or wathever the name may be) that can generate 4, 10, 17 buttons, all with different targets..
I just need to learn how to find witvh one of the generated buttons was pressed (in the Generator script each Button, I mean, each MCInstant with a Button! is named "nBT" + n).
When I discover with "n" button was pressed I target the "n" Instant/frame/page, eg: if The Final User pressed the "nBT" + 6 button then the Script will redirect a certain part of the page (most likely a MC and a textbox) to the MC_number6 (first unloading the first one, of course) and displaying the 6th textbot.
I wish to know:
- How can I know witch MC (I don't even need to use any code regarding the button) the user has pressed, if it's the "nBT"+1 or the "nBT"+4,nothing else , I know the rest of the code:
while (n < The number of generated buttons)
If (The pressed MC of a Button == "nBT"+n) then I will display the MC/frame/whatever that is located on "page" n
.........
Another simple thing (I hope) is how knowing witch button the user has pressed (5 for eg.) will I load, let us say..... how will It open Http://www.BlaBla.com/page5.htm ?
I've tried using the target "Http://www.blabla.page" & 5 but It won't budge... and if I say that it's an expression it will just load something like http://"http://www.blabla.page"%20%&%20%5...
Help....
webguy
09-25-2003, 12:40 PM
this.onPress = function () {
// keep a global variable to say who was pressed
_global.currentClip = this;
}
// now you can use currentClip as a reference to the button pressed
currentClip.enabled = false;
// for example
You can make your loaded movies have the same name as your instance this will make it easy to associate them with each other. Here is an example.
// we have a clip onStage called advert (_root.advert);
_root.advert.onPress = funciton () {
trace(this._name) // traces advert
getUrl("http://www.mydomain.com/"+this._name+".html");
// equates to http://www.mydomain.com/advert.html
}
There are many other ways to associate your clips with external assets by utilizing set naming conventions like above. You can also substring your instance name and use part of the name.
You can also use associate arrays, or multidimensional arrays.
clipNames = [advert,home,stats];
extNames = ["advertising.html","index.html","statistics.html"];
clipNames[1].onPress = function () {
getUrl("http://www.mydomain.com"+extNames[1]);
}
/* same as:
home.onPress = function () {
getUrl("http://www.mydomain.com/index.html");
}
*/
web
Moralez
09-25-2003, 12:46 PM
Thank You! I'll get right on it!
EDIT: I did it :-)
This is the code I user, well, part of..
on (press) {
_global.Pressed = this;
x= 0;
while (x<_root.n) {
if (Pressed == _root["nBT"+x;
stop();
}
x=x+1;
}
The part where it loads the page is located in aonther button, all for debug and teste reasong, thank you for all the help!
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.