A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: XML preloader

  1. #1
    Senior Member
    Join Date
    Nov 2006
    Posts
    162

    XML preloader

    I have a question

    I have a slideshow loading XML data. The XML file is pretty simple: image, title, desc, link X 4.

    What I need is a preloader that looks for when the IMAGE is loaded and not the XML file. All I could find was for preloading the XML file, which I dont need.

    I want to listen for when the image is loaded, then once it is loaded add the text and other components to the stage.

    Can someone direct me to some good info out there?

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    All you need to do is add an event listener.

    myLoader.contentLoaderInfo.addEventListener(Event. COMPLETE, compHandler);
    function compHandler(event:Event):void
    {
    //all your text etc here
    }

    I am doing a bit of guessing, since you did not provide any code.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member
    Join Date
    Nov 2006
    Posts
    162
    Thanks cancerinform,

    I think that is what I was looking for. But if I am to display a preloader as well, would there be a different approach?

    I could always fake it and have the preloader in the background and have the image overlap, but if there is a different way I would be happy to know!

    Thanks

  4. #4
    Senior Member
    Join Date
    Nov 2006
    Posts
    162
    So now it works perfectly locally, but when I upload it, the images either dont load or appear and disappear right away.

    DO you know what is going wrong? I cannot figure out :-(

    Loading the first image:

    Code:
    xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
    
    function xmlLoaded(event:Event):void
    {
    	xml = XML(event.target.data);
    	xmlList = xml.children();
    
    	loader.load(new URLRequest(xmlList[0].image));
    	texts_mc.title_txt.text = xmlList[0].title;
    	texts_mc.desc_txt.text = xmlList[0].desc;
    	xmlLink = xmlList[0].link;
    
    	loader.contentLoaderInfo.addEventListener(Event.COMPLETE, compHandler);
    	function compHandler(event:Event):void
    	{
    		addChildAt(loader, 1);
    		bar_mc.play();
    
    	}
    
    }
    Then playing the slides:
    Code:
    	loader.addEventListener(Event.ENTER_FRAME, loadImg);
    
    	function loadImg(event:Event):void
    	{
    		if (bar_mc.currentFrame == 30)
    		{
    			loader.load(new URLRequest(xmlList[i].image));
    			TweenLite.to(loader, .5, {alpha:1});
    
    			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, compHandler);
    			function compHandler(event:Event):void
    			{
    				trace("loaded");
    				addChildAt(loader, 1);
    				bar_mc.gotoAndPlay(1);
    			}
    			texts_mc.title_txt.text = xmlList[i].title;
    			texts_mc.desc_txt.text = xmlList[i].desc;
    			xmlLink = xmlList[i].link;
    		}
    	}
    
    }
    This is only the part of the code that loads the images. If you need to see the whole thing let me know.

    Also when I trace, it gives me a weird result (trace "i" and when it give the complete handler) It repeats I dont know why? Maybe that is the part that is bugging?:

    1
    loaded
    loaded
    2
    loaded
    loaded
    loaded
    loaded
    loaded
    loaded
    3
    loaded
    loaded
    loaded
    loaded
    loaded
    loaded
    loaded
    loaded
    loaded
    loaded
    loaded
    loaded


    Thanks!

  5. #5
    Junior Member
    Join Date
    Jul 2010
    Posts
    3
    Just forwarded this onto a friend who is great at coding and integrating xml. will let you know if I get a helpful reply

  6. #6
    Senior Member
    Join Date
    Nov 2006
    Posts
    162
    Thank you bilgaraden.

    Do you guys think it would be because of this event listener the issue:

    bar_mc.addEventListener(Event.ENTER_FRAME, loadImg);

    I need to present this tomorrow and I feel helpless right now...

  7. #7
    Senior Member
    Join Date
    Nov 2006
    Posts
    162
    So if I remove the event listener for the loader to load, it works, but then I am back to square one with NO preloader. Is there a way to create a preloader or an event listener that only plays the bar once the image is finished loading?

    Actionscript Code:
    bar_mc.addEventListener(Event.ENTER_FRAME, loadImg);

        function loadImg(event:Event):void
        {
            if (bar_mc.currentFrame == 30)
            {
                loader.load(new URLRequest(xmlList[i].image));
                TweenLite.to(loader, .5, {alpha:1});
                //addChildAt(loader, 1);
                bar_mc.gotoAndPlay(1);
                trace("loaded");

  8. #8
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You can get a Preloader here:
    http://www.flashscript.biz/flashas3/...Preloader.html
    There is an example given. You need to download the classes by clicking on the link on the left of the menu.
    - The right of the People to create Flash movies shall not be infringed. -

  9. #9
    Senior Member
    Join Date
    Nov 2006
    Posts
    162
    ok thanks I will check it out.

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