A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: [F9] Bitmap Loading from Library

  1. #1
    Heli Attack! iopred's Avatar
    Join Date
    Jun 2003
    Location
    Sydney, Australia
    Posts
    923

    [F9] Bitmap Loading from Library

    Has anyone figured out a clean way to get Bitmap loading through code in the Flash 9 Alpha?

    The embed method that worked in Flex is spitting errors at me, auto-generating a class from the library doesn't want to work, and I really don't think making an MC for every bitmap is the best way around it.

    So has anyone had any luck with it? Or should I just chalk it down to it being an Alpha?
    Christopher Rhodes
    squarecircleco.

  2. #2
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    Hmmm, I know I've seen this somewhere, but I can't remember where. I'll let you know once I find it again.

  3. #3
    Member
    Join Date
    May 2006
    Posts
    70
    I don't know for certain, but if you can't attach the bitmap directly to the display list, you may have to create a sprite through code and attach it to the sprite first. Then you can attach it to the display list. I will check this to see if it works.

  4. #4
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    Okay, I just did some testing, and here's the deal. I imported a bitmap, and set it to export for as, with an auto-generated class called Test.
    If you do var t:Test=new Test(), you get a reference to it, but it extends BitmapData, which isn't a DisplayObject, so you can't just do whatever.addChild(Test). You'll have to create an empty Bitmap, and set it's bitmapData reference to your object. Then you can use that bitmap.

    Seems to work fine.
    Last edited by Fall_X; 07-21-2006 at 04:25 PM.

  5. #5
    Member
    Join Date
    May 2006
    Posts
    70
    Yeah something like this:

    Code:
    var image:test = new test();
    var mysprite:Sprite = new Sprite();
    mysprite.graphics.beginBitmapFill(image);
    mysprite.graphics.drawRect(0, 0, 100, 100);
    mysprite.graphics.endFill();
    addChild(mysprite);

  6. #6
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    Why use beginBitmapFill when you have the Bitmap class for this? Just use :

    Code:
    var image:Test = new Test();
    var bmp:Bitmap=new Bitmap();
    bmp.bitmapData=image;
    this.addChild(bmp);
    or, a bit shorter :

    Code:
    var bmp:Bitmap=new Bitmap();
    bmp.bitmapData=new Test();
    this.addChild(bmp);

  7. #7
    Heli Attack! iopred's Avatar
    Join Date
    Jun 2003
    Location
    Sydney, Australia
    Posts
    923
    Ah, it's BitmapData *slap*

    code:

    var bmp:Bitmap = new Bitmap(new Test());
    this.addChild(bmp);



    Works too, if you guys wanted the quickest way, thanks for the help guys.
    Last edited by iopred; 07-21-2006 at 07:40 PM.
    Christopher Rhodes
    squarecircleco.

  8. #8
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    Didn't realize you could pass Bitmap a BitmapData object in the constructor, nice. But if you want the shortest way, this is even shorter, lol :

    Code:
    var bmp:Bitmap = this.addChild(new Bitmap(new Test()));

  9. #9
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Moved to AS3 forum.

  10. #10
    Junior Member
    Join Date
    Jul 2007
    Posts
    1

    Error

    I keep getting the error - Label must be a simple identifier any ideas?

    Cheers,

    Sarah

  11. #11
    Member
    Join Date
    May 2006
    Posts
    70
    What does your code look like?
    Last edited by jason merchant; 07-18-2007 at 03:50 AM.

  12. #12
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    You can find an example here:
    http://www.senocular.com/flash/tutor...3withflashcs3/
    download the source files and check the tutorial about half way down page 2.

    Note that Flash CS3 has changed this behavior (from Flash 9 alpha) and now requires that the width and height params be used for the new BitmapData instance

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