Create MovieClip and Linkage in Script

I need to load pictures from the local folder into movie clips at the beginning of the project and then attach the movie clips to place holders at various places.

This is simple to do if the images are already embedded into the SWF file during design time, since I can assign a linkage name and then simply use attachMovie to 'load' them into a placeholder.

How can I do this dynamically during run-time. The issue here is that I can't allow the loading of the image to take place prior to just displaying them. The load process needs to take place right at the beginning.

Thanks for any code suggestions!

JB
jsoundAsked:
Who is Participating?
 
Jakob_EConnect With a Mentor Commented:
Hi JB,

Perhaps this will work for you:

// Create an array holding the images you want to load
var arrImages = new Array()
arrImages[0] = "http://www.experts-exchange.com/images/woman_orange.jpg"
arrImages[1] = "http://www.experts-exchange.com/images/expertPic.jpg"

// Create a container clip to hold the loaded images
container = createEmptyMovieClip("container",0)

// Run thru the images in your array
for (var i = 0; i<arrImages.length; i++){
  // For each image create a new empty movieclip
  this = container.createEmptyMovieClip("image"+i,i)
  // Load the image into the newly created clip
  this.loadMovie(arrImages[i])
  // Assign the newly created clip to your image array (replacing the path)
  arrImages[i] = this
  // Set alpha = 0
  arrImages[i]._alpha = 0
}

// Now when you want to display an image in your conatiner
// simply refer to the arrImages[x] raising alpha to 100 like:

arrImages[0]._alpha = 100


Best, Jakob E
 

0
 
BillystyxCommented:
so load them and then set the visible quality of the container clip to false at the start of the movie.
Just make them visible when you want them.

Billystyx
0
 
BillystyxCommented:
container.loadMovie("mypic1.jpg");
and when it has loaded:

container._visible=false;

Billystyx
0
 
jsoundAuthor Commented:
I appreciate the suggestion. Thought about that one too. However, the problem is that it's the same container that I need to be swapping the movie clips in. In other words, each image must be contained in a separate movie clip that is dynamically created. Those movie clips are then attached to the said container clip.

Hope this makes sense...

JB
0
 
jsoundAuthor Commented:
Thanks, Jakob. This will be a good workaround. I would have preferred a solution that allowed me to create a movie clip AND specify a linkage name for the clip. However, it seems that Flash Actionscript doesn't have support for that. I may be wrong, but I haven't seen anything, thus the question.

Thanks,

JB
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.