0 Replies Latest reply on Sep 19, 2006 5:23 AM by Methlor Gor

    Dynamic Functions & Internet Explorer - Not Working

    Methlor Gor Level 1
      I've created an application that uses a virtual playhead. The virutal timeline consists of an array populated with functions. Buttons that directly call a specific function (e.g. Play, or End) work fine in I.E., but buttons that call a dynamic function (e.g. Previous or Next) do not work in I.E.


      The programmer goes in and manipulates a blank Object called “Stages” by adding properties entitled:

      stage1, stage2, stage3, (etc . . . ), finalStage, and fullPlay

      Each of these stages is assigned a function. All of the properties of Object “Stages” are then parsed into an array called “stageArray.” In this manner, I am able to populate an array with functions.

      The program works fine when I directly call a function in the manner below:

      myButton.onRelease = function() {

      Stages.stage1();
      //The function executes as expected
      }

      The problem occurs in IE when I try to dynamically call a function. Dynamic function calls work fine in Flash Player, Firefox, et al . . .

      currentPlay = 0;
      var theFunction = stageArray[currentPlay];
      this[theFunction].call();

      I hope this is enough for you to work with. I’ve attached a copy of the relevant code. Thank you again for looking at this with me.

      //CODE

      //Declare variables used in Virtual Playhead
      var completePlay:Object = new Object();
      var currentPlay:Object = new Object();

      /********** VIRTUAL PLAYHEAD CONTROLS**********/
      //This code works – it directly references a function
      PlayBar.Rewind_btn.onRelease = function() {
      Stages.stage1(); //Direct reference of function
      currentPlay = 0; //Resets playhead to zero
      }

      //This code does not function – it dynamically references a function
      PlayBar.Previous_btn.onRelease = function() {
      currentPlay -= 1; //Subtracts 1 from “currentPlay”
      var theFunction = stageArray[currentPlay].toString();
      Stages[theFunction].call();
      }

      //Again, this works since it directly references a function
      PlayBar.Play_btn.onRelease = function() {
      Stages.fullPlay();
      }


      PlayBar.Next_btn.onRelease = function() {

      currentPlay += 1; //Adds one to currentPlay
      var theFunction = stageArray[currentPlay];
      Lesson.Stages[theFunction].call();
      }

      //Again, this works since it directly references a function
      PlayBar.End_btn.onRelease = function() {
      Stages.finalStage();
      }


      //The playhead itself is an imported file – imported at runtime
      this.onLoad = function() {

      //The following declares the object “Stages” and then various properties are assigned to “Stages”
      //These properties are then declared as functions.
      //The concept is for the object Stages to have any number of functions as defined by the //programmer

      //NOTE: the code below actually exists as a totally separate external file that is imported at //runtime. For the purposes of this demonstration, I have included it in the Playhead example

      var Stages:Object = new Object(); //Declare “Stages” Object
      Stages.stage1 = function() { //Property Function of Stages
      //function data
      };

      Stages.stage2 = function() { //Property Function of Stages
      //function data
      };

      Stages.finalStage = function() { //Property Function of Stages
      //function data
      };

      //Function declared to play entire sequence
      Stages.fullPlay = function() { //Property Function of Stages
      substage1 = function () {
      //function data
      };

      substage2 = function () {
      //function data
      };

      subfinalStage = function () {
      //function data
      };

      setTimeout(substage2, 0);
      setTimeout(subfinalStage, 4500);
      };
      }
      //Parses through all of the “Stages” Functions and assigns them to the array "stageArray"
      for ( var i in Lesson.Stages) {
      stageArray.push(i);
      }
      stageArray.reverse(); //Reverses order of stageArray so that it counts up from [0]

      //Removes last function (fullPlay) since it is directly referenced by “Play” button
      //and not part of the “Next” and “Previous” button sequence
      completePlay = stageArray.pop();

      //Set Playhead to zero
      currentPlay = 0;

      //define the variable “theFunction” as a particular item in the array “stageArray”
      var theFunction = stageArray[currentPlay];

      //Use the “call” method to call the “theFunction”
      this[theFunction].call();
      }