see this
http://anujmehrotra.info/amazingflash/slidextreme/
this is how it works for me…
exactly what you want to do… (sorry there is no preloader… you just have to wait a bit for the images to load)… but thats what you meant…
private function onXMLLoaded(success:Boolean)
{
if (success)
{
var TOTAL_ITEMS:Number = DATAML.firstChild.childNodes.length;
for (var i:Number = 0; i < TOTAL_ITEMS; i++)
{
var ptr:XMLNode = DATAML.firstChild.childNodes*;
var slide:Object = new Object();
slide.id = ptr.childNodes[0].firstChild;
slide.description = ptr.childNodes[1].firstChild;
slide.icon = String(ptr.childNodes[2].firstChild);
slide.big = String(ptr.childNodes[3].firstChild);
RECORD_STORE.push(slide);
}
render();
}
}
private function render():Void
{
// create clips dynamically
var iconHolder:MovieClip = CONTENT.createEmptyMovieClip("icon" + iconCounter, CONTENT.getNextHighestDepth());
iconHolder._x = ICON_X;
var icListener:Object=new Object();
var icLoader:MovieClipLoader = new MovieClipLoader();
icListener.onLoadInit = Delegate.create(this, setIcon);
icLoader.addListener(icListener);
icLoader.loadClip(String(RECORD_STORE[iconCounter].icon), iconHolder);
iconCounter++;
}
private function setIcon(target:MovieClip):Void
{
target._y = (slideScroller._height/2)-(target._height/2);
ICON_X += target._width + 5;
MovieClip(target).onRelease = loadBigImage;
MovieClip(target).onRollOver = FXin;
MovieClip(target).onRollOut = FXout;
if (iconCounter <= RECORD_STORE.length - 1)
{
render();
}
else
{
BigImageLoader(0);
}
}
Explaination:
-
onXMLLoaded parses the xml and stores the data in an array.
-
Next it calls render();
-
render() creates a empty movieclip on stage and loads the first image from the array
using MovieClipLoader
-
onLoadInit setIcon is called
-
setIcon vertically centers the movieclip because now i have the width and height as target.
-
ICON_X is a global variable which is set to the next image position using .
ICON_X += target._width + 5;
-
iconCounter is also a global variable which is set to 0 is the begining
as each icon is loaded iconCounter is incremented by 1.
-
the code checks if iconCounter is < items in array (meaning more items remaining)
it once again calls setIcon and hence we have a synchronized mechanism to load and position all the images.
[quote=tbear2008;2333011]Hi all,
I’m having trouble with some code.
I using a loop to dynamically create some movieclips and then position them using the ._height and .width values.
When they are created I use a Listener and LoadInit, to check that everything has loaded. I do this because I want to be able to access the ._height properties of the movieclip in order to place them next to each other and centre them vertically.
If I place the following 3 lines outside the function:
inBead._x = currentPosition;
//gets the start position
currentPosition = currentPosition+Number(mainLoader._width);
//gets the position and adds the width of the movieclip
inBead._y = composite_start_pos_y-(mainLoader._height/2)
//gets the initial position and then centres the movieclip
It always regards the width and height values of the movieclips as 0, which suggests that it is checking this before the LoadInit has been done, and so the movieclips all display one on top of each other.
If I place them inside this function, my movieclips are never displayed.
I’m not what’s causing the problem, any help would be immensley appreciated! The full code is below:
function displayAll() {
var inBead:MovieClip;
currentPosition = composite_start_pos_x;
for (var i = 0; i<=beadsOnComposite; i++) {
inBead = _root.mySlider.attachMovie(“inside_bead_object”, stripX2(band*[0])+i, i);
inBead.bead_name = band*[0];
inBead.bead_price = band*[1];
inBead.bead_loc = band*[2];
inBead.bead_size = band*[3];
inBead.bead_id = band*[4];
inBead.beadHH = band*[5];
inBead.bead_position = i;
if (inBead.bead_loc == undefined) {
removeMovieClip("_root.mySlider.undefined");
} else {
var mcLoader:MovieClipLoader = new MovieClipLoader();
var mcListener:Object = new Object();
var mainLoader = _root.mySlider[stripX2(band*[0])+i].createEmptyMovieClip(“loader”,this.getNextHighestDepth())
mcLoader.addListener(mcListener);
mcLoader.loadClip(inBead.bead_loc, mainLoader);
mcListener.onLoadInit = function(target:MovieClip){
inBead._x = currentPosition;
currentPosition = currentPosition+Number(mainLoader._width);
inBead._y = composite_start_pos_y-(mainLoader._height/2)
}
};
};[/quote]