Skip to main content
Sharpe D
Known Participant
December 13, 2021
Answered

Advice for variables, data in Animate - Canvas

  • December 13, 2021
  • 2 replies
  • 294 views

I am working on an airplane demo with lots of variables/ data which is growing quickly. And as the demo has grown it is become unweildy workign with variable/ data. So I am workign to create a plane demo with somewhat workign guages. As user goes through project, questions - answers change the plane guage settings. I currenly just have variables in name value pairs and basic functions switching values on guages.

 

I want to simplify staorage of variables. And functions to change the variables/ data. One thing to mention, some variables on the guages are shared on other guages, like altitude is on three guages. Also as the user goes through questions and makes changes. Not all the data is changed. A question may change a handful of variables. 

 

Any recomendations on setup. A reference on a setup. I was thinking an array for data. And a loop for the questions to call function changing certain variables.

 

    This topic has been closed for replies.
    Correct answer kglad

    setObj("altitude",16700);

    setObj("throttle", 450);

     

    altitude.text=getObj("altitude");

    throttle.text=getObj("throttle");

    2 replies

    Sharpe D
    Sharpe DAuthor
    Known Participant
    December 14, 2021

    This is helpful direction. I have an array of information. I am having trouble getting the array information into specific text fields on the stage or movie clips. 

     

    planeArray = Altitude "16700", Throttle "450"

     

    then

     

    altitude.text = 16700

    trottle.text = 450

     

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    December 14, 2021

    setObj("altitude",16700);

    setObj("throttle", 450);

     

    altitude.text=getObj("altitude");

    throttle.text=getObj("throttle");

    kglad
    Community Expert
    Community Expert
    December 14, 2021

    use a javascript object:

     

    ///// begin setup //////

    const dataObj = {};

    function setObj(key,value){
    dataObj[key] = value;
    }
    function getObj(key){
    return dataObj[key];
    }

    ///// end setup //////


    // usage
    setObj("altitude",10000);  // assign a key
    getObj("altitude");   // retrieve value