dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: Loader Event/loading external bitmaps

  1. #1
    Senior Member
    Join Date
    Oct 2009
    Posts
    112

    [RESOLVED] Loader Event/loading external bitmaps

    [RESOLVED ] I have my .fla file and .swf file in a folder on my desktop

    i want to add to that file a bitmap. everytime my flash project receives a the String "loadBITMAP" i want it to reload that bitmap into a designated area on the stage.
    (i am using a system of binary sockets to recieve data, but don't worry about that...i know how to process that already.)
    so basically my code will say
    Code:
    if(socket.readUTFBytes="loadBitmap"){
            need code here on how to load bitmap
    }
    does that make sense? thanks for the help!
    Last edited by mattwatts15; 12-03-2009 at 08:44 AM. Reason: mark as RESOLVED

  2. #2
    AS2 intolerant person
    Join Date
    Jan 2009
    Location
    Swansea
    Posts
    352
    Code:
    var loader:Loader;
    loader.load(new urlRequest('url goes here'));
    addChild(loader);
    thats for loading from url, i dont know what your socket thing is meant to do for it though.

    flos

  3. #3
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    thanks....when it loads that bitmap, where will it go? how do i tell it where to load on the stage???

  4. #4
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    The bitmap will come in as a child of the loader - you can move the loader around wherever you need it or access loader.content to get the actual Bitmap out.
    Please use [php] or [code] tags, and mark your threads resolved 8)

  5. #5
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    sorry whats the child of the loader? when i put that code in nothing happens that i can see on the stage....im new to as3 so i dont understand a lot

  6. #6
    Member
    Join Date
    Sep 2008
    Posts
    80
    it's gonna add the bitmap into the stage (where you can see it)

    i think you have to use
    use loader.x=whatever number or loader.y=whatever number to position to bitmap.

  7. #7
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    ok that makes sense. but i tried it and it says "error #1009 cannot access a property or method of a null object reference."

  8. #8
    Member
    Join Date
    Sep 2008
    Posts
    80
    that happens most of the time when you are wrting the AS code in the wrong frame, before a movieclip is used or using the wrong variable name

    can you give us more code so we can help you?

  9. #9
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    if you're just loading an image, you can reference the loader and it'll move position or be added to the display list as is described above. but if you're creating an actual Bitmap object from an instance of a BitmapData object, it's different.

    if you position the loader, but have created a bitmap, they're different things. you need to add that Bitmap object to the stage, and can position it just like you'd position anything else.

    when you get the bitmap data, you make a bitmap:
    PHP Code:
    var bmp:Bitmap = new Bitmap(whatever.bitmapData); 
    and can now use that Bitmap object like any other display object
    PHP Code:
    someContainer.addChild(bmp);
    bmp.100;
    bmp.100

  10. #10
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    Code:
    var loader:Loader;
    loader.load(new URLRequest('C:\Documents and Settings\Peter\Desktop\D32 64\sp logo.bmp'));
    addChild(loader);
    var bmp:Bitmap = new Bitmap('C:\Documents and Settings\Peter\Desktop\D32 64\sp logo.bmp');
    bmpContainer.addChild(bmp);
    bmp.x=1127.0;
    bmp.y=220.0;
    thats the combined code of things i've tried so far...obviously thats not gonna do anything. is there a way to do something like this:
    Code:
    var loader:Loader;
    loader.load(new URLRequest('C:\Documents and Settings\Peter\Desktop\D32 64\sp logo.bmp'));
    addChild(loader);
    loader.x=1127.0;
    loader.y=220;

  11. #11
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    if you don't want a Bitmap object (capital "B") and are just loading an image, the last bit of code you posted would be the best approach.

    that said, flash can't handle .bmp files. JPG, PNG or GIF only, AFAIK.

  12. #12
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    wait so in my URL, where the file is labeled .bmp, does that mean it wont load that at all, since it's a bitmap?

    and u said that last bit of code would be the best approach. unfortunatley that IS my best approach, it's not working, and i dont know where to go from there.....

    when i say its not working i mean im getting this error
    Code:
    error #1009 cannot access a property of a null object reference
    Last edited by mattwatts15; 12-02-2009 at 06:14 PM. Reason: clarify error

  13. #13
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    you just forgot to instantiate it (new Loader()), should look like this: (note the change on the first line)
    PHP Code:
    var loader:Loader = new Loader();
    loader.load(new URLRequest('C:\Documents and Settings\Peter\Desktop\D32 64\sp logo.bmp'));
    addChild(loader);
    loader.x=1127.0;
    loader.y=220
    BUT!! it still won't work, since flash can't load .bmp files - only jpg, png and gif.

  14. #14
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    ok i changed it to JPEG.

    it's saying "URL not found" now....i double checked the URL, my .fla project is in the same folder as the JPEG image...so why would it say that?

  15. #15
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    ok nevermind there was a problem with my URL adress, but now i'm getting ANOtHER error:

    file type is unknown...but i though JPEG is fine? or is jpg and JPEG two different things?

  16. #16
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    its working now!

  17. #17
    ___________________
    Join Date
    May 2004
    Posts
    3,174

  18. #18
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    is there a way to stop loading an image? such as loader.stop();

  19. #19
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    i think it's loader.close();
    but its not working....when i click the button to close a loader, it doesnt stop...

  20. #20
    Member
    Join Date
    Sep 2008
    Posts
    80
    what is the loader.close for???to delete the swf??

    i think you have to use somethign like removeChild("name_of_the loader");
    loader.close();
    loader.unload();

    source
    http://www.flepstudio.org/forum/flas...t-working.html

Tags for this Thread

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