A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: HELP!! Need to load images with XML...

  1. #1
    Brian Monnone
    Join Date
    Jul 2000
    Posts
    316

    HELP!! Need to load images with XML...

    I need to find out how to load images with XML...it's kind of a long story but I need to be able to laod them viw XML. I know VERY little about XML and Flash...any help would be greatly appreciated!

    Thanks in advance,

    - Sigma

  2. #2
    Brian Monnone
    Join Date
    Jul 2000
    Posts
    316
    Ok I got one image to load correctly(works good too!)...I need to load 6 images into am image scroller I'm working on....I just can't figure out how to get the other images in my XML doc to load in...any help is greatly appreciated!

    - Sigma

  3. #3
    Jace Masula
    Join Date
    Apr 2000
    Posts
    100
    stack the images in an array, and access them like this

    MyXML[0].attributes.imageName
    MyXML[1].attributes.imageName

    etc...
    post some code from your XML doc, and ill give ya an example script

  4. #4
    Brian Monnone
    Join Date
    Jul 2000
    Posts
    316
    Hey thanks for the reply! I got the images to load in correctly. I got the images to also scroll with the mouse movement. Now my problem is that whenever I move the mouse up then down (or vice versa) the images begin to whack out! Meaning, the alignment of the images begin to slip out of place...very strange! I'm sure it has to do with some sort of equation in the XML but I have no clue! Here is a link to what I have so far:

    http://www.tocquigny.net/temp_xml_scroller/

    Move the mouse to the top of scroll, getting it scrolling fast, hold it there for about 15 secs...then move the mouse to the bottom and do the same...you'll start to see the images begin to lose vertical alignment!

    ANY help would be greatly appreciated!!

    - Sigma

  5. #5
    Jace Masula
    Join Date
    Apr 2000
    Posts
    100
    i seen what ur talking about.

    PHP Code:
    imageXml = new XML();
    imageXml.ignoreWhite true;
    imageXml.onLoad = function(success) {
        if (
    success) {
            
    menuItem this.firstChild.childNodes;
            for (var 
    i=0i<menuItem.lengthi++) {
                
    item scroller.image.attachMovie("imageClip""imageClip" ii);
                
    item._x 0;
                
    item._y 150*i;
                
    item.myImage menuItem[i].attributes.image;
                
    item.loadInto.loadIntoMain.loadMovie(item.myImage);
                
    menuItemLength menuItem.length 150;
                
            
    item.onEnterFrame = function(){
                
    yMousePos = -_ymouse;
                
    this._y += yMousePos/10;
                if(
    this._y>150*i){
                    
    this._y 0;    
                }
                if(
    this._y<0){
                    
    this._y 150*i;    
                }
            }
            
            }
        }
    }
    imageXml.load("myImages.xml"); 
    whats this line for?
    menuItemLength = menuItem.length * 150;
    Last edited by Flash Ninja; 10-07-2002 at 12:45 PM.

  6. #6
    Brian Monnone
    Join Date
    Jul 2000
    Posts
    316
    Heh! I put that there thinking I was going to capture the height then scroll with it...actually that should be deleted or commented out.

    So what do you think? I really appreciate you looking at it.

    Sigma

  7. #7
    Jace Masula
    Join Date
    Apr 2000
    Posts
    100
    .length is used to return the length of a variable string.

    for example
    Jace = "happy"
    digits = Jace.Length

    trace(digits); would return the number 5

    alright, this is my guess as to whats happening here.

    you are evaluating the placement of each and every movieclip (image)that is displayed. Im sure if you only call in 3 or 4 images, those gaps wont happen. if you call in 100+ images, those gaps will be HUGE and the images will overlap and such. i think this is because your code is processor intensive. each clip that u duplicate contantly is checkin for its position using the onclip. so as you scroll up and down, any processor lag that occurs, offsets the true _ymouse value. since your function is using an evalualtion of the _ymouse, each clip is dependent on that value, and thus dependent on the processor speed.

    solution...

    duplicate the movieclip images INSIDE a larger movieclip. THEN scroll THAT larger one that contains all of the smaller ones. this will remove the need to reposition each image clip according to _ymouse because the scrolling is handled by the larger MC.
    so... try rewriting the duplication script to incorporate the image clip container.

    but before you do, try this first cause im not sure this is correct.

    PHP Code:
    u have
    for (var i=0i<menuItem.lengthi++)
    does menuitem.length return the number of childnode or the length of the string????

    maybe try this insteadits check to see if the value of the image NOT null.
    for (var 
    i=0menuItem[i].attributes.imagei++) { 
    hope this help alittle

  8. #8
    Brian Monnone
    Join Date
    Jul 2000
    Posts
    316
    Hey Flash Nija I appreciate the help that may work and I'll try it. I emailed my buddy Robert Penner. (I hate bothering him) He got it to work in about 30 mins...he truly rocks.. Here is his solution:

    imageXml = new XML();
    imageXml.ignoreWhite = true;
    imageXml.onLoad = function(success) {
    if (success) {
    menuItem = this.firstChild.childNodes;
    for (var i=0; i<menuItem.length; i++) {
    item = scroller.image.attachMovie("imageClip", "imageClip" + i, i);
    item._x = 0;
    item.y = item._y = 150*i;
    item.myImage = menuItem[i].attributes.image;
    item.loadInto.loadIntoMain.loadMovie(item.myImage) ;
    //menuItemLength = menuItem.length * 150;

    item.onEnterFrame = function(){
    yMousePos = -_ymouse;
    switch (mspeed){
    case mspeed<1:
    mspeed=1;
    break;
    case mspeed>100:
    mspeed=100;
    break;
    }
    this.y += yMousePos*mspeed/100;
    if(this.y>150*i){
    this.y -= 150*i;
    }
    if(this.y<1){
    this.y += 150*i;
    }
    this._y = this.y;
    }


    }
    }
    }
    imageXml.load("myImages.xml");


    (I added the switch statment for my component)

    MANY props to Penner, once again.

    Thanks again FN!

    - Sigma
    Last edited by Sigma; 10-07-2002 at 06:04 PM.

  9. #9
    Jace Masula
    Join Date
    Apr 2000
    Posts
    100
    just for fun, copy and paste about 100 or so entries into your XML doc and see how the script runs. Im curious to see if moving 100 clips or so will slow or lag the script down.

    but cool

  10. #10
    Brian Monnone
    Join Date
    Jul 2000
    Posts
    316
    Hey, I copied about 120 XML lines for 120 images and sure enough it slowed considerably. But I'm fine with that though, I really don't think people will load in 100 images into this thing. It's main purpose that I can see is a small portfolio section or navigation of some sort.

    Thanks for the help again.

    Sigma

  11. #11
    Aallow! what's owll this then? iqevil's Avatar
    Join Date
    Aug 2001
    Location
    London Town
    Posts
    141
    Are there any tutorials on this anywhere... will be greatly appreciated.

    Thanks!

  12. #12
    Brian Monnone
    Join Date
    Jul 2000
    Posts
    316
    Tutorial on creating a scroller like this? Kinda confused about what part your asking about..

    - Sigma

  13. #13
    Aallow! what's owll this then? iqevil's Avatar
    Join Date
    Aug 2001
    Location
    London Town
    Posts
    141
    Just tutorials on how to load images in flash using xml... pretty much the same stuff you created.

    Thanks

    iq

  14. #14
    Brian Monnone
    Join Date
    Jul 2000
    Posts
    316
    I'm sure there are some step by step instructions out there. I unfortunatly dont have the time put one together right now but I have created a quick example you can DLed form my site: www.monnone.com/stuff/fk_loadimages.zip

    This is a mutation from something I found a while back. I couldn't find it again so I don't know the original authors name so I can't give credit to that person. If you recognize this as yours then props to you!

    Anyway, study this set of files, you'll get, it's really not that hard at all. I stripped out all the unessasary BS code so you can learn from it!

    Good luck!

    - Sigma

  15. #15
    Aallow! what's owll this then? iqevil's Avatar
    Join Date
    Aug 2001
    Location
    London Town
    Posts
    141
    You're a life saver!!
    A very big thanks for all the trouble you went through I really appreciat it.

    Thanks again

    iq

  16. #16
    Brian Monnone
    Join Date
    Jul 2000
    Posts
    316
    Sure, no problem. I don't mind helping! I sometimes need help myself so I understand totally! Let me know if that helps you out any.

    - Sigma

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center