onLoadInit() Help

Hey guys, Im trying to make a horizontal scroller, that pulls images from an XML document, and scrolls them infinitely.

I have 2 problems with this and I have been looking everywhere for a tutorial, or example that shows how to do this and I always find something that is close to what I want but not quite.

Here is what I have so far:


var mcLoader:MovieClipLoader = new MovieClipLoader();        
var mcListener:Object = new Object();

for(i=0; i<main.length; i++){
        var mainLoader = loader_mc.createEmptyMovieClip("loader"+i, i);
               
        mcLoader.addListener(mcListener);        
        mcLoader.loadClip(main*.attributes.url, mainLoader);
        mcListener.onLoadInit = function(target:MovieClip){
             trace(mainLoader); //returns loader_mc.loader11, 11 times.
        };        
        
        mainLoader._y = 225;
        mainLoader._x = loader_mc["loader"+(i-1)]._x + [U]490[/U];
                
    };
       
    onEnterFrame = function(){
        loader_mc._x = loader_mc._x - 3;
    };

What I’m wanting to do is instead of using 490 (underlined), I want to be able to get the width of each loaded image so that I can line up the next image right up against it regardless of its width (490 just happens to be the width of all of them right now).

I’m trying to use the onLoadInit() function, but I know I’m doing something wrong. When I try and trace my mainLoader variable, it traces the right amount of times, but they are all the last object in the group.

What do I need to do to be able to get the widths of each image as it loads, then use that variable to position the next image right after it?

also (a semi unrelated help request), what I’m doing right now is loading them ALL in creating one giant line of images, then loading in another giant line of images and just alternating between the 2 each time one is almost to the end of its length. Is there a better way to do this so that only the right amount will load, and scroll, at the beginning adding the one right before it enters stage, and as they move off stage they are removed, then when it’s near the end it just adds the first one back to the end?

Sorry for the HUGE wall of text, but this problem is starting to frustrate me.

Thank you for all of your help.

have all function OUTSIDE the forloop.
example, the onLoadInit shouldbe outside

okey like this:
[AS]
var mcLoader:MovieClipLoader = new MovieClipLoader();
var mcListener:Object = new Object();
mcLoader.addListener(mcListener);
mcLoader.loadClip(main*.attributes.url, mainLoader);
mcListener.onLoadInit = function(target:MovieClip){
trace(target); //returns loader_mc.loader11, 11 times.
};
mainLoader._y = 225;
for(i=0; i<main.length; i++){
var mainLoader = loader_mc.createEmptyMovieClip(“loader”+i, i);

    mainLoader._x = loader_mc["loader"+(i-1)]._x + 490;
            
};
   
onEnterFrame = function(){
    loader_mc._x = loader_mc._x - 3;
};

[/AS]

wops i se some errors, but i cant edit, try to see them by yourself

Thanks for your response it feels like thats one step closer, but I’m still not sure how to use the widths now to be able to position each of the loaded images.

The scope of my variable “i” is unique to my for loop and can’t be used in the onLoadInit function, and it seems like anything I do in the onLoadInit is unique to the scope of that function. So how am I supposed to use either of the 2 together to position the images using the width?

Sorry if I seem to be asking simplistic questions, but I must just be missing something, or it’s just not clicking or something, but I’m still feeling kind of lost.

function intro(){
    var main = intro_xml.firstChild.childNodes;
    
    var mcLoader:MovieClipLoader = new MovieClipLoader();        
    var mcListener:Object = new Object();
    
    loader_mc._alpha = 0;
    
    mcLoader.addListener(mcListener);
    mcListener.onLoadInit = function(target:MovieClip){
        //I'm still not sure what to put here so that I can set the x position of each of my images based off of the width of the previously loaded image.
    };
    for(i=0; i<main.length; i++){
        var mainLoader = loader_mc.createEmptyMovieClip("loader"+i, i);

        mainLoader._y = 225;
        mcLoader.loadClip(main*.attributes.url, mainLoader);
    };
    Tweener.addTween(loader_mc, {_alpha:100, time:5, transition:"easeOutExpo"});
    
    onEnterFrame = function(){
        loader_mc._x = loader_mc._x - 3;
    };
};

didnt want to read all your text, im very tired, but is this what your looking for?
[AS]

for(i=0; i<main.length; i++){
var mainLoader = loader_mc.createEmptyMovieClip(“loader”+i, i);
mainLoader._x = i500
mainLoader._y = 225;
mcLoader.loadClip(main
.attributes.url, mainLoader);
};
[/AS]

import mx.utils.Delegate;

var ICON_Y:Number;
var ICON_X:Number = 5;
var gapping=10;
var mcLoader:MovieClipLoader;
var mcListener:Object;
var dataarray=new Array();

// assuming that dataarray now holds images from some xml…

var i=0;

function createThumbs()
{
if(i<=dataarray)
{
var imageHolder:MovieClip=this.createEmptyMovieClip(“clip”+i,i);
mcLoader=new MovieClipLoader();
mcListener=new Object();
mcListener.onLoadInit=Delegate.create(this,onImageLoad);
mcLoader.addListener(mcListener);
mcLoader.LoadClip(String(dataarray*),imageHolder);
}
}

function onImageLoad(target:MovieClip)
{
target._x=ICON_X;
ICON_X=target._x+gapping+target._width;
i++;
// you can add your tween code here
createThumbs();
}

/// Explaination

the above code assumes that you have a a array called dataarray, that holds the image urls.

Now we initialize i=0; and begin loading the first image. when the image loads we get the width of the image with onLoadInit function. Note that it is essential to generate the movieclips dynamically as :


var imageHolder:MovieClip=this.createEmptyMovieClip("clip"+i,i);

next we increment the x axis using ICON_X variable in the onLoadInit function.
and then start loading the next image by calling createThumbs(); untill all the images are loaded.

:slight_smile:

[quote=switchBack;2324284]Hey guys, Im trying to make a horizontal scroller, that pulls images from an XML document, and scrolls them infinitely.

I have 2 problems with this and I have been looking everywhere for a tutorial, or example that shows how to do this and I always find something that is close to what I want but not quite.

Here is what I have so far:


var mcLoader:MovieClipLoader = new MovieClipLoader();        
var mcListener:Object = new Object();

for(i=0; i<main.length; i++){
        var mainLoader = loader_mc.createEmptyMovieClip("loader"+i, i);
               
        mcLoader.addListener(mcListener);        
        mcLoader.loadClip(main*.attributes.url, mainLoader);
        mcListener.onLoadInit = function(target:MovieClip){
             trace(mainLoader); //returns loader_mc.loader11, 11 times.
        };        
        
        mainLoader._y = 225;
        mainLoader._x = loader_mc["loader"+(i-1)]._x + [U]490[/U];
                
    };
       
    onEnterFrame = function(){
        loader_mc._x = loader_mc._x - 3;
    };

What I’m wanting to do is instead of using 490 (underlined), I want to be able to get the width of each loaded image so that I can line up the next image right up against it regardless of its width (490 just happens to be the width of all of them right now).

I’m trying to use the onLoadInit() function, but I know I’m doing something wrong. When I try and trace my mainLoader variable, it traces the right amount of times, but they are all the last object in the group.

What do I need to do to be able to get the widths of each image as it loads, then use that variable to position the next image right after it?

also (a semi unrelated help request), what I’m doing right now is loading them ALL in creating one giant line of images, then loading in another giant line of images and just alternating between the 2 each time one is almost to the end of its length. Is there a better way to do this so that only the right amount will load, and scroll, at the beginning adding the one right before it enters stage, and as they move off stage they are removed, then when it’s near the end it just adds the first one back to the end?

Sorry for the HUGE wall of text, but this problem is starting to frustrate me.

Thank you for all of your help.[/quote]