Scottiedazzle
07-26-2005, 09:17 PM
Help! :eek:
I am at my wit's end here. The following code works like a charm for creating a variable from the positition of the current frame, turning that variable into the name of a movie clip, then applying a function to that movie clip (in this case, loading text into a TextArea component).
textloader = function () {
var holeidentity = Math.floor((_currentframe + 3)/4); //rounds product down to determine hole number
var holestring:String= "0" + holeidentity;//turn holeidentity into a string
if (holestring.length == 2) {
var currenthole = holestring.substr(0, 2);//pulls 2 digit string out of 2 digit number
} else {
var currenthole = holestring.substr(1, 2);//pulls 2 digit string out of 3 digit number
}
//code for loading text deleted
}
var holeidentity = Math.floor((_currentframe + 3)/4); //rounds product down to determine hole number
var holestring:String= "0" + holeidentity;//turn holeidentity into a string
if (holestring.length == 2) {
var currenthole = holestring.substr(0, 2);//pulls 2 digit string out of 2 digit number
} else {
var currenthole = holestring.substr(1, 2);//pulls 2 digit string out of 3 digit number
}
if (((_currentframe/4)-holeidentity) == .25) {
var currentlocation = "tee";
} else if (((_currentframe/4)-holeidentity) == -.75) {
var currentlocation = "tee";
} else if (((_currentframe/4)-holeidentity) == .5) {
var currentlocation = "fairwaya";
} else if (((_currentframe/4)-holeidentity) == -.5) {
var currentlocation = "fairwaya";
}else if (((_currentframe/4)-holeidentity) == .75) {
var currentlocation = "fairwayb";
} else if (((_currentframe/4)-holeidentity) == -.25) {
var currentlocation = "fairwayb";
} else {
var currentlocation = "green"
}
currenthole_mc = "hole" + currenthole + currentlocation + "1_mc";
textloader.apply(currenthole_mc);
This formula will figure out where it is in the timeline, accordingly determine what text to load, then load the text. It even figures out what movie clip instance it is being applied to, so it will load the right text. :)
So, why won't this work for a button action on the main timeline? :( The only difference that I see between the two functions is that the variable currentbutton, which is determined the same way the variable currenthole_mc is in the above example, cannot have an action (onRollOver) applied to it.
interactivebtnA= function () {
var holeidentity = Math.floor((_currentframe + 3)/4); //rounds product down to determine hole number
var holestring:String= "0" + holeidentity;//turn holeidentity into a string
if (holestring.length == 2) {
var currenthole = holestring.substr(0, 2);//pulls 2 digit string out of 2 digit number
} else {
var currenthole = holestring.substr(1, 2);//pulls 2 digit string out of 3 digit number
}
if (((_currentframe/4)-holeidentity) == .25) {
var currentlocation = "tee";
} else if (((_currentframe/4)-holeidentity) == -.75) {
var currentlocation = "tee";
} else if (((_currentframe/4)-holeidentity) == .5) {
var currentlocation = "fairwaya";
} else if (((_currentframe/4)-holeidentity) == -.5) {
var currentlocation = "fairwaya";
}else if (((_currentframe/4)-holeidentity) == .75) {
var currentlocation = "fairwayb";
} else if (((_currentframe/4)-holeidentity) == -.25) {
var currentlocation = "fairwayb";
} else {
var currentlocation = "green"
}
var currentbutton = "hole" + currenthole + currentlocation + "1_btn"
currentbutton.onRollOver = function () {
//The function has trouble calculating what currentbutton is!!
}
currentbutton.onRollOut = function () {
//The function has trouble calculating what currentbutton is!!
}
}
var holeidentity = Math.floor((_currentframe + 3)/4); //rounds product down to determine hole number
var holestring:String= "0" + holeidentity;//turn holeidentity into a string
if (holestring.length == 2) {
var currenthole = holestring.substr(0, 2);//pulls 2 digit string out of 2 digit number
} else {
var currenthole = holestring.substr(1, 2);//pulls 2 digit string out of 3 digit number
}
if (((_currentframe/4)-holeidentity) == .25) {
var currentlocation = "tee";
} else if (((_currentframe/4)-holeidentity) == -.75) {
var currentlocation = "tee";
} else if (((_currentframe/4)-holeidentity) == .5) {
var currentlocation = "fairwaya";
} else if (((_currentframe/4)-holeidentity) == -.5) {
var currentlocation = "fairwaya";
}else if (((_currentframe/4)-holeidentity) == .75) {
var currentlocation = "fairwayb";
} else if (((_currentframe/4)-holeidentity) == -.25) {
var currentlocation = "fairwayb";
} else {
var currentlocation = "green"
}
var currentholeA_btn = "hole" + currenthole + currentlocation + "1_btn"
interactivebtnA.apply(currentholeA_btn);
Is there something simple that I am missing? I am still learning arrays and such, so the use of variables is the best solution that I can think of to tell a function which instance of a button the actions should be applied to.
Any help would be greatly appreciated! :o
I am at my wit's end here. The following code works like a charm for creating a variable from the positition of the current frame, turning that variable into the name of a movie clip, then applying a function to that movie clip (in this case, loading text into a TextArea component).
textloader = function () {
var holeidentity = Math.floor((_currentframe + 3)/4); //rounds product down to determine hole number
var holestring:String= "0" + holeidentity;//turn holeidentity into a string
if (holestring.length == 2) {
var currenthole = holestring.substr(0, 2);//pulls 2 digit string out of 2 digit number
} else {
var currenthole = holestring.substr(1, 2);//pulls 2 digit string out of 3 digit number
}
//code for loading text deleted
}
var holeidentity = Math.floor((_currentframe + 3)/4); //rounds product down to determine hole number
var holestring:String= "0" + holeidentity;//turn holeidentity into a string
if (holestring.length == 2) {
var currenthole = holestring.substr(0, 2);//pulls 2 digit string out of 2 digit number
} else {
var currenthole = holestring.substr(1, 2);//pulls 2 digit string out of 3 digit number
}
if (((_currentframe/4)-holeidentity) == .25) {
var currentlocation = "tee";
} else if (((_currentframe/4)-holeidentity) == -.75) {
var currentlocation = "tee";
} else if (((_currentframe/4)-holeidentity) == .5) {
var currentlocation = "fairwaya";
} else if (((_currentframe/4)-holeidentity) == -.5) {
var currentlocation = "fairwaya";
}else if (((_currentframe/4)-holeidentity) == .75) {
var currentlocation = "fairwayb";
} else if (((_currentframe/4)-holeidentity) == -.25) {
var currentlocation = "fairwayb";
} else {
var currentlocation = "green"
}
currenthole_mc = "hole" + currenthole + currentlocation + "1_mc";
textloader.apply(currenthole_mc);
This formula will figure out where it is in the timeline, accordingly determine what text to load, then load the text. It even figures out what movie clip instance it is being applied to, so it will load the right text. :)
So, why won't this work for a button action on the main timeline? :( The only difference that I see between the two functions is that the variable currentbutton, which is determined the same way the variable currenthole_mc is in the above example, cannot have an action (onRollOver) applied to it.
interactivebtnA= function () {
var holeidentity = Math.floor((_currentframe + 3)/4); //rounds product down to determine hole number
var holestring:String= "0" + holeidentity;//turn holeidentity into a string
if (holestring.length == 2) {
var currenthole = holestring.substr(0, 2);//pulls 2 digit string out of 2 digit number
} else {
var currenthole = holestring.substr(1, 2);//pulls 2 digit string out of 3 digit number
}
if (((_currentframe/4)-holeidentity) == .25) {
var currentlocation = "tee";
} else if (((_currentframe/4)-holeidentity) == -.75) {
var currentlocation = "tee";
} else if (((_currentframe/4)-holeidentity) == .5) {
var currentlocation = "fairwaya";
} else if (((_currentframe/4)-holeidentity) == -.5) {
var currentlocation = "fairwaya";
}else if (((_currentframe/4)-holeidentity) == .75) {
var currentlocation = "fairwayb";
} else if (((_currentframe/4)-holeidentity) == -.25) {
var currentlocation = "fairwayb";
} else {
var currentlocation = "green"
}
var currentbutton = "hole" + currenthole + currentlocation + "1_btn"
currentbutton.onRollOver = function () {
//The function has trouble calculating what currentbutton is!!
}
currentbutton.onRollOut = function () {
//The function has trouble calculating what currentbutton is!!
}
}
var holeidentity = Math.floor((_currentframe + 3)/4); //rounds product down to determine hole number
var holestring:String= "0" + holeidentity;//turn holeidentity into a string
if (holestring.length == 2) {
var currenthole = holestring.substr(0, 2);//pulls 2 digit string out of 2 digit number
} else {
var currenthole = holestring.substr(1, 2);//pulls 2 digit string out of 3 digit number
}
if (((_currentframe/4)-holeidentity) == .25) {
var currentlocation = "tee";
} else if (((_currentframe/4)-holeidentity) == -.75) {
var currentlocation = "tee";
} else if (((_currentframe/4)-holeidentity) == .5) {
var currentlocation = "fairwaya";
} else if (((_currentframe/4)-holeidentity) == -.5) {
var currentlocation = "fairwaya";
}else if (((_currentframe/4)-holeidentity) == .75) {
var currentlocation = "fairwayb";
} else if (((_currentframe/4)-holeidentity) == -.25) {
var currentlocation = "fairwayb";
} else {
var currentlocation = "green"
}
var currentholeA_btn = "hole" + currenthole + currentlocation + "1_btn"
interactivebtnA.apply(currentholeA_btn);
Is there something simple that I am missing? I am still learning arrays and such, so the use of variables is the best solution that I can think of to tell a function which instance of a button the actions should be applied to.
Any help would be greatly appreciated! :o