Add properties dynamically from strings


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. var mc:MovieClip = new MovieClip(); // make new object
  2.  
  3. // these strings can come from flashvars, arrays etc
  4. var n:String = "tallness"; // this is the property
  5. var v:String = "100 miles"; // this is the value for the property
  6.  
  7. // assign the property and value at the same time
  8. mc[n] = v;
  9.  
  10. trace(mc.tallness); // traces: 100 miles

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.