views:

56

answers:

1

I am trying to dynamically tween some movieclips in my SWF but have problems with their dynamically created names. Here is the code

function slidePhoto(e:TimerEvent):void {
    i = "i3";
    movieClip = i as Object;
    Tweener.addTween(movieClip,{x:0, y:0, transition:"easeInOutQuint", time:1, onComplete:waitMe, onCompleteParams:[4000, slideOutPhoto]});
}

Even if I declare

var i:String = "i";
var movieClip:Object;

and then

movieClip = i+3;

this doesn't work, but if I trace movieClip I get "i3" ??? Is this casting problem or am I somewhere very very wrong?

+2  A: 

Hi Zlatiborac, try this:

function slidePhoto(e:TimerEvent):void {
    i = "i3";
    movieClip = getChildByName(i);
    Tweener.addTween(movieClip,{x:0, y:0, transition:"easeInOutQuint", time:1, onComplete:waitMe, onCompleteParams:[4000, slideOutPhoto]});
}

Locate getChildByName at this reference page:

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html

This isn't a casting problem, you simply need to locate the DisplayObject based on the name contained in i.

Jotham
When I try this and then trace movieClip I receive null as a result
Zlatiborac
Yes as Jotham and Lior said at the moment you are trying to convert a string to an object and somehow use that to reference a MovieClip which is never going to work. Jotham's solution will work. I suspect that you have not named your MovieClip. When you create a MovieClip dynamically you will need to set the name property. So myMC:MovieClip = new MovieClip(); myMC.name = i3. It also must be added to the display list.
Allan
Well, just after importing Tweener I defined those objects as MovieClipsimport caurina.transitions.Tweener;stop();var i1:slika1 = new slika1();i1.name = "i1";var i2:slika2 = new slika2();i2.name = "i2";as you can see I've gave them names, but once again this doesn't work.When I trace movieClip and typeof I get i3 and string ... String is Object type, and Tweener manual states that I need Object as target... but this doesn't work...
Zlatiborac
You need to call getChildByName() on the DisplayObjectContainer that holds your 'slika' instances - the same object on which you call "addChild(i1);" or similar.
Sly_cardinal
I suggest you upload a zip of your files somewhere for us.
Jotham
Jotham