Normally for a string to object is converted as follows.
var obj:object=getChildByName("string");
And we can give properties to it like obj.x=100;But in the case of a series of stings
[objet Stage].[object MainTimeline].[object TextField]
it wil not works.Actually i need to give properties to a target path which is a string
what i do??
Here is the code to get path to a movieclip:
addEventListener(MouseEvent.CLICK, targetMC);
function targetMC(MouseEvent:Event):void
{
var curinstance = MouseEvent.target.valueOf();
var targ:Object = curinstance.parent;
var path = curinstance;
do
{
if (targ == "[object Stage]")
{
path = targ + "." + path;
}
else
{
path = targ + "." + path;
}
targ = targ.parent;
} while (targ);
trace(path);
}
i would like to give properties to path.
A number of things are awkward about your code:
Don’t compare the string value of objects to find out about class type. Use the
iskeyword:Don’t use class names as parameter names: MouseEvent is a type!
It is useful to name handler methods according to the event upon which they are invoked, for example:
or
If you can avoid it, don’t cast to
Objectto access members, but try to use subclass types – it allows the compiler to more effectively check your code for errors. Since all objects in the display list are instances ofDisplayObject, you could use this:If you want to output a path to your object, use instance names instead of types – you might have more than one TextField!
Now for your answer: Use the KeyboardEvent.
and
Note that this will only work as long as the TextField has focus, that is the user has to click it first.