View Full Version : Pass a string, return object with name string
doublemazaa
August 21st, 2008, 04:02 PM
I feel like this should be pretty easy, but I 'm not quite sure how to do this...
I've got a string that is the name of a movieclip which is on the stage. I'd like to write a function which I can pass that string and have it return the object which has the instance name of that string.
Any hints?
Thanks.
John
wvxvw
August 21st, 2008, 04:12 PM
function findDisplayObjectOnTheStage(objectName:String):Dis playObject
{
return stage.getChildByName(objectName);
} =)
doublemazaa
August 21st, 2008, 04:36 PM
Thanks! That's exactly what I needed.
Any advice on this? I've got the name of a movieclip, I'm trying to set it equal to another movie clip, but AS is worried because getChildByName returns a DisplayObject. Anyway to reassure AS that I'll actually be calling movieclips and not other display objects.
newThumb.widePic = stage.getChildByName(myXML..widePic[index])
Error 1118: Implicit coercion of a value with static type flash.display:DisplayObject to a possibly unrelated type flash.display:MovieClip.
wvxvw
August 21st, 2008, 04:51 PM
(someDisplayObject as MovieClip).gotoAndPlay(1)
or
MovieClip(someDisplayObject).gotoAndPlay(1)
But if someDisplayObject is not MovieClip this will generate runtime error.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.