A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: How to dynamically derive a variable's value

  1. #1
    Join Date
    Dec 2002

    How to dynamically derive a variable's value

    In my FLA I have a MC called imageController. Into the imageController MC I load some variables from a .txt file - one such variable is numEventsImages=3. There's another variable called sectionName = Events;

    I have a function called count in the first frame of the main timeline, and it uses both variables.

    QUESTION: When I invoke the count function within the imageController MC, how can I *dynamically* get the value of numEventsImages.

    I know that I can get it by referring directly to the loaded variable: trace("numEventsImages: " + imageController.numEventsImages);

    But I want to do it dynamically, but when I try:
    trace("numEventsImages (derived): " + "num" + imageController.sectionName + "Images");
    all I get is the *string* numEventsImages.

    and when I try:
    trace("numEventsImages (derived): " + this["num" + imageController.sectionName + "Images"]);
    I get nothing from the trace. I've also tried it with eval.

    Thanks for your help.

  2. #2
    Secret Agent
    Join Date
    Sep 2000
    San Francisco, CA
    derVar="num" + imageController.sectionName + "Images";
    trace("numEventsImages (derived): " + eval(derVar) );

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center