Forums: Flash:

 

Controlling dynamically named movie clips

first
 

jestros Controlling dynamically named movie clips

So I load an array of img names from php, loop through it, create a movie clip and place the img in it. I have figured out how to control the properties of the clip, but I need to be able to get into more depth with it. So here's a snipit of what I have so far:


for (i=0; i<c; i++) {
_root.a = myImgArray[i];
_root.err = "/images/imglib/lil"+myImgArray[i];
_root.gallery.createEmptyMovieClip("mc"+i, i);
loadMovie("/images/imglib/lil"+myImgArray[i], "_root.gallery.mc"+i);
setProperty(eval("_root.gallery.mc"+i), _x, thumbX + 80);
thumbX += 80;
}


Which places the thumbnails across the stage. The things I'd like to get into that I can't figure out are transitions with onData, so when they load they come in with a transition. And onRelease to make them all clickable.
I can't target the movie clip with _root.gallery.mc+i.onData or _root.gallery.mc[i].onData.

 

DontBogartMe

yeah hi, nice to meet you too.

What you're looking for is
_root.gallery["mc"+i].onData


and I'd add that your code is waaaaay out of date and you'd benefit from learning some newer stuff, like at least Flash MX... or AS2... or even AS3. 'eval' is dead. 'setProperty' is deader.

"anything invented before you were 18 has been there forever, anything that turns up before you're 30 is new and exciting, and anything after that is a threat to the world and must be destroyed."

quote
 

jestros

I got the setProperty from flash 8 help. I figured out another way to do it, which is naming the clip like:
mc = _root.gallery.createEmptyMovieClip("mc"+i, i);
so, and then controlling mc as normal. BUT, doing a little research, you cant use onData with loadmovie (only loadvariables), you must attach onClipEvent(data) to an actual movie clip on the stage. Which doesn't work for me, because I need to load these things dynamically. OMGWTFBBQ. I know there's a work around for this.

 

Hideaway

I made this a while back... may not me the cleanest in the world, but it works similar to what you're looking for


//ObjectLoader.as

import mx.transitions.*;
import mx.transitions.easing.*;

class ObjectLoader
{
private static var speed:Number = 1; // fade the clip in over 1 second

public static function LoadObject(path:String, targ:MovieClip, callbackfunc:Function, initFunc:Function):MovieClip
{
var holder:MovieClip;
var callback:Function = function ():Void
{
holder = targ.createEmptyMovieClip("objectholder", targ.getNextHighestDepth());
//
var mcLoader:MovieClipLoader = GetMovieClipLoaderObject(callbackfunc, initFunc);
mcLoader.loadClip(path, holder);
};

callback();

return holder;
}
private static function GetMovieClipLoaderObject(callback:Function, initFunc:Function):MovieClipLoader
{
var loadListener:Object = new Object();
//
loadListener.onLoadError = function(target_mc:MovieClip, errorCode:String, httpStatus:Number)
{
trace(">> loadListener.onLoadError()");
trace(">> ==========================");
trace(">> errorCode: " + errorCode);
trace(">> httpStatus: " + httpStatus);
};
//
loadListener.onLoadComplete = function(target_mc:MovieClip, httpStatus:Number):Void
{
SetFade(1, target_mc, callback);
if(initFunc != null) initFunc();
};
//
loadListener.onLoadInit = function(target_mc:MovieClip):Void
{
};
//
loadListener.onLoadStart = function(target_mc:MovieClip)
{
target_mc._alpha = 0;
};
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(loadListener);
//
return mcLoader;
}
public static function SetFade(dir:Number, targ:MovieClip, callback:Function):Void
{
var dest:Number = (dir < 0) ? 0 : 100;
var tween:Tween = new Tween(targ, "_alpha", None.easeIn, targ._alpha, dest, speed, true);
tween.onMotionFinished = function()
{
callback();
};
}
}


Now, in your code, you could do something like the following...


for (i=0; i<c; i++) {
var img:String = "/images/imglib/lil" + myImgArray[i]; // I assume myImgArray[i] == a string
var padding:Number = 10;

var completeCallback:Function = function():Void
{
// do something as soon as the image has fully loaded
}

var callback:Function = function():Void
{
//do something after the image has completely faded in
}

var mcHolder = _root.gallery.createEmptyMovieClip("mc"+i, _root.getNextHighestDepth());

var imgClip:MovieClip = ObjectLoader.LoadObject(img, mcHolder, callback, completeCallback);

imgClip._x = (80 + padding) * i;
}


Try something to that affect...


I love boots. It's like midgets hugging my calves...
quote
 

jestros

Hideaway, you rock bro! I'm doing a little dance right now. It's crazy that you need that much code for something that should be built in to flash. Iffun I could just use onData!
I've read over your class a few times, learned a lot.
I think I'll actually stop being so lazy, and start spelling out var name:Type.

BTW, I guess I'm pretty new here, but I used to post under jestros WAY back in the day on WH.

 

JLM

Hideaway,

your code may work, but...

onLoadComplete fires when the bytes are loaded.

onLoadInit fires when properties are avaliable.

So it is best to use onLoadComplete for getting the next asset in a sequence and inLoadInit for any tweening in.




jestros

welcome to the barrel and twelvestone, might be worth getting a few books to get up to speed on flash code.





 

Hideaway

Good to know... Thanks JLM...

I love boots. It's like midgets hugging my calves...
quote
 

JLM

No worries I only picked it up from a actionscript tutorial I am no guru I just spent too long trawling the internet, I am now trying to work out the ins and outs of as3 and maybe even flex will it never end!

 
first
 

Forums: Flash: Controlling dynamically named movie clips

 
New Post
 
You must be logged in to post