Copy link to clipboard
Copied
I have a MovieClip that contains a Dynamic Text lable with a string value:
I want to use the value of prodID to populate a string of code, variables are set up here:
pID = this.prodID.text;
That returns CHEMLOK289290286
and next:
tID = "t_" + pID;
That creates t_CHEMLOK289290286 which is a variable and should display its value of: Chemlok® 289/290 where referenced;
This is the executed script:
this.pBTN.b_Title.text = tID;
Instead of displaying the var's value, it displays "t_CHEMLOK289290286" in the button label.
It should instead display Chemlok® 289/290 as it does with the hand coded script:
this.pBTN.b_Title.text = t_CHEMLOK289290286;
Shouldn't this.pBTN.b_Title.text = tID; be the exact equivalent of that hand coded script?
next line:
this.pBTN.addEventListener("click", pID.bind(this));
That should render as CHEMLOK289290286.bind but it does not, instead it errors: Uncaught TypeError: pID.bind is not a function...
Shouldn't that script be identical to the hand coded script that works as expected, here?
this.pBTN.addEventListener("click", CHEMLOK289290286.bind(this));
Is it not possible to compose scripts populated by values of variables? I can find no information anywhere of this being done, any insight, helpful hints or clues are welcome.
Thanks.
Copy link to clipboard
Copied
pID will be fixed once your first line of code executes.
do you want pID to change when the text in the textfield this.prodID changes
Copy link to clipboard
Copied
pID will be fixed once your first line of code executes.
Fixed as in static or corrected?
This is one of a collection of product buttons, so each button has it's own code and visual identifier (prodID) which I want to also serve as a source to modify its script.
Right now the product buttons contain script such as:
this.pBTN.b_Title.text = t_CHEMLOK289290286;
this.pBTN.addEventListener("click", CHEMLOK289290286.bind(this));
...which works just fine, but to save some time, since every button will have it's own visual identifier (prodID) anyway, I think a version of that script that uses info found in prodID would be better, where I could avoid having to paste in the prodID three times, when one time would do.
Thanks.
Copy link to clipboard
Copied
fixed as in static. ie, as the text changes, pID remains the same.
but you may be asking a different question, but i can't tell exactly what you're asking. i now think it may be that you're asking how to coerce a variable to be an object (eg, movieclip or function). if so, you would use bracket notation.
for example:
//////////////////////////////////
var f = "some_string";this[f] = function(){
console.log(f);
}
this.some_string();
this[f]();
/////////////////////////////////////
or
///////////////////////////////////////
// if you have an onstage object instanceName
var f = instanceName.name; // ie, a string
console.log(this[f] == this.instanceName); // true
this[f]