Dynamic! "createEmptyMovieClip"

I am trying to dynamically create movie clips.


newYPosition = 100
arrayDay = "A day that comes from a data base"
for (i=0; i-1<this.NUMITEMS; i++) {

newYPosition = newYPosition + 100
banner = "banner"+arrayDay

createEmptyMovieClip(banner, 0);
banner.loadMovie("Dynamic_Calendar_banner.swf");
	banner._x = 200;
	banner._y = newYPosition;
}

I get no movie clips when I run this code. I do not think flash likes it when I creating the variable “banner”, and then inserting it into the createEmptyMovieClip command as the movie clip’s name.

I have also tried this:


newYPosition = 100
arrayDay = "A day that comes from a data base"
for (i=0; i-1<this.NUMITEMS; i++) {

newYPosition = newYPosition + 100

createEmptyMovieClip("banner"+arrayDay, 0);
banner.loadMovie("Dynamic_Calendar_banner.swf");
	"banner"+arrayDay._x = 200;
	"banner"+arrayDay._y = newYPosition;
}

I get an error stating flash does not like this code
banner+arrayDay._x = 200;
banner+arrayDay._y = newYPosition;
It says, “Left side of assignment operator must be variable or property”

Is there a way to make this work?

What are you trying to do?

The reason the first piece isn’t working is because of the depth problem i think. plus I don’t think you’re using createEmptyMovieClip correctly. Try something like:

[AS]
_root.createEmptyMovieClip(“new”+i,i+3);
eval("_root.new" +i).loadMovie(“whatever.swf”);

[/AS]

Do you see what Im going with this? you are putting the new MCs in an appropriate place first and then referencing back to that location to do further operations.

lemme know if this helps.

Shaheeb R.

This is how I am using your code ahmonra:


_root.createEmptyMovieClip("new"+i,i+3);
eval("_root.new" +i).loadMovie("whatever.swf");
eval("_root.new" +i)._x = 200;
eval("_root.new" +i)._y = newYPosition;

I get one movie clip that I can see. I think they are all stacked on top of eachother because when I look at the variable list I see that all of the movie clips have loaded. So what do you think about the y positioning?

What I am trying to do is create a list of ads that stack vertically on top of each other. The ads can be updated on the back end so when you hit refresh on this end you will see the new ad. All of this was successful when I was using cgi to dynamically generate an html page that had tables in them that called my swf. I would rather use flash for this because if I don’t, then I will have to use frames in the website. Makes me think of a side question, can you put html on top of a flash file. As far as I know you can’t, but I can dream.)

This might be a silly question, but are you incrementing newYPosition? try running a trace on the Y position and see that its working the way you want it. Unless I’m missing something, what you have right now should work.

Also somethings to watch out for: pick a high number for the depth before you start creating the MCs. because if there are any mcs on the stage before starting the loop, that could trip you up a little.

If the incrementing is all good, then I hope you should be set to go.

Shaheeb R.

My Bad, The Y position is working just fine. I was setting the postion to 100 inside of the loop.

:thumb:

Thanks!! ahmonra