79253135

Date: 2024-12-05 01:14:16
Score: 2.5
Natty:
Report link

How to convert a string to an object identifier and then retrieve/get property values for that object? There is two ways to do this in ActionScript:

  1. We can use the eval() function:

eval(targetAsString.IDName); or eval(_root.targetAsString.IDName);

  1. We can use the array-access operator:

_root[targetAsString].IDName; or _root[targetAsString]["IDName"];

Notice how I use a string to target the value of the property, by using array-access operator [] multiple times.

I would recommend to use the the array-access operator over the eval() function because it's faster and less processor intensive. It's also a more secure solution.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Contains question mark (0.5):
  • Unregistered user (0.5):
  • Starts with a question (0.5): How to
  • Low reputation (1):
Posted by: ZicZac