dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: CS3: Loading a PNG with AS3 - sometimes loads, sometimes does not [renamed]

  1. #1
    Junior Member
    Join Date
    May 2007
    Posts
    11

    CS3: Loading a PNG with AS3 - sometimes loads, sometimes does not

    I am seriously considering throwing my pc out the window!!!
    Okay I am trying to load a simple png. Sometimes it works sometimes it doesn't, WHY!!! Either work all the time or do not work all the time!!! Anyway here is my code. It worked last night but this morning it does not load anything.

    import flash.display.*;
    import flash.net.URLRequest;
    import flash.events.Event;
    var container:Sprite = new Sprite();
    container.x = 0;
    container.y = 250;
    addChild(container);
    var pictLdr:Loader = new Loader();
    var pictURL:String = "flyfire.png"
    var pictURLReq:URLRequest = new URLRequest(pictURL);
    pictLdr.load(pictURLReq);
    pictLdr.contentLoaderInfo.addEventListener(Event.C OMPLETE, imgLoaded);
    function imgLoaded(event:Event):void
    {
    container.addChild(pictLdr.content);
    }

  2. #2
    Actionscript 3, postproduction georgecalgary's Avatar
    Join Date
    Jun 2005
    Location
    Toronto
    Posts
    229
    Why you want to add listener to .contentLoaderInfo? 'a LoaderInfo object corresponding to the object being loaded.' It possibly add your listener to a null object before your image being loaded.

    pictLdr.contentLoaderInfo.addEventListener(Event.C OMPLETE, imgLoaded);

  3. #3
    Actionscript 3, postproduction georgecalgary's Avatar
    Join Date
    Jun 2005
    Location
    Toronto
    Posts
    229
    Try this.
    pictLdr.addEventListener(Event.COMPLETE, imgLoaded,false,0,true);
    function imgLoaded(event:Event):void
    {
    container.addChild(pictLdr.content);
    pictLdr.removeEventListener(Event.COMPLETE, imgLoaded);
    }

  4. #4
    Junior Member
    Join Date
    May 2007
    Posts
    11
    I still can't get it to work.

  5. #5
    Junior Member
    Join Date
    May 2007
    Posts
    11
    btw the squirell bubble game needs a warning about addiction possibilities -
    thats how I just spent my past 2 hours

  6. #6
    Actionscript 3, postproduction georgecalgary's Avatar
    Join Date
    Jun 2005
    Location
    Toronto
    Posts
    229
    Sorry for your hours. hehe.

    Well I'm too busy these days I forget myself used the same .contentLoaderInfo to add listener. I have a class I wrote 6 months before you could use to load images. It works fine.

    http://www.neatfilm.com/flash/download/ImageLoader.as

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