A Flash Developer Resource Site

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

Thread: working with bitmaps?

  1. #1
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    working with bitmaps?

    Ok trying to use a bitmap sheet of playing cards but am having trouble getting the bitmapData thing to work..

    From the Flash online docs I got the following:
    Code:
    var linkageId:String = "libraryBitmap";
    var myBitmapData:BitmapData = BitmapData.loadBitmap(linkageId);
    trace(myBitmapData instanceof BitmapData); // true
    
    var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
    mc.attachBitmap(myBitmapData, this.getNextHighestDepth());
    I modified it for KM as:
    I have a Movieclip in the library with a bitmap graphic loaded and the link name is set to 'deck'
    Code:
    myBitmapData = flash.display.BitmapData.loadBitmap("deck");
    
    var mc = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
    mc.attachBitmap(myBitmapData, this.getNextHighestDepth());
    But this doesn't work. I check and myBitmapData is undefinded after that first line so something in the first line is wrong or something else needed to make it work.

    Anyone shed some light here? (Wilbert?)

  2. #2
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Ah I see part of the problem, From AS docs Notation:
    loadBitmap work only with bitmap data, but not with instances of symbol (MovieClip, Button, Graphic) in library.
    Therefore, allways for this method use source(imported) bitmaps in library
    We cannot load bitmaps into the symbol library...... Looking..........

  3. #3
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    pretty sure this:


    myBitmapData = flash.display.BitmapData.loadBitmap();


    has to be this:


    myBitmapData = new flash.display.BitmapData.loadBitmap();

  4. #4
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Ultimately I want to load in a deck of cards on a "sprite sheet" and pull cards to display them when needed.

  5. #5
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Probobly their bitmapdata_puzzle would be a good start towards that. It already slices a master bitmap into whatever dimensions you decide and has the drag and drop (with detection of where) you would most likely need also encompassed and would be the fastest path to the goal (maybe) using existing examples.

  6. #6
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Thanks Chris. Funny thing is that was from MM docs

    Oh and oddly the link you supplied was blocked from the public access connection I'm at right now due to "pornography" Which I thought was funny. Don't know where they get that..... THey are using something called St Bernard filtering software... Odd

  7. #7
    Senior Member
    Join Date
    Jun 2000
    Posts
    3,512
    We cannot load bitmaps into the symbol library...... Looking..........

    -> Yes you can through the action script editor.

  8. #8

  9. #9
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    The right syntax is
    myBitmapData = flash.display.BitmapData.loadBitmap();
    without new. It's a bit confusing since if you want to create a new bitmap, you do need to use new
    myBitmapData = new flash.display.BitmapData();
    I made the mistake several times adding new while it shouldn't be there and wondering why the bitmap wouldn't load.

    Bob is right that you can add bitmaps to the symbol library using the link icon in the actionscript editor.
    It works fine.

  10. #10

  11. #11
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Ok finally back to this topic,

    I still can't get this working right. the following code:
    Code:
    import flash.display.BitmapData;
    myImage= BitmapData.loadBitmap("logo")
    //myImage=new BitmapData(200,200,false,0xffcc00cc)
    this.createEmptyMovieClip("disp",this.getNextHighestDepth());
    disp.attachBitmap(myImage,disp.getNextHighestDepth())
    works in Flash, both the uncommented loadBitmap and the commented Created bitmap work.

    yet in KM it just doesn't work, I know wilbert has done this in his sprite example but I cannot follow his code very well.

    Here's what I've got so far:
    Code:
    //myImage= flash.display.BitmapData.loadBitmap("logo")
    myImage=new flash.display.BitmapData(200,200,false,0xffcc00cc)
    this.createEmptyMovieClip("disp",this.getNextHighestDepth());
    disp.attachBitmap(myImage,disp.getNextHighestDepth())
    I do have a bitmap image loaded in the symbol library via the actionscript editor.

    Perhaps this is just not the way to go for this project idea.
    Last edited by blanius; 11-28-2006 at 02:56 PM.

  12. #12
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Your code works fine for me Bret.
    Are you sure you got the link name of the image right and the movie is exported as flash 8 ?

  13. #13
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Dang it I bet is was export not set again.

  14. #14
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    That's not the first time that's gotten me.

  15. #15
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Hey Wilbert, to use this for like a sprite sheet. Do I have to first load a image into a bitmapData object then load that into a movieclip and then copy the part I want to yet another bitmapData object to then copy out to display movieclip?

  16. #16
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Ok getting there, I'm over the bitmap hurdle at least now on to the rest of the game
    http://www.bretlanius.com/flash/videopoker.html

    Press the button to advance the card

    this is just a test output at this point, getting a sheet of playing card graphics cut and put into a clip one at a time as needed.

  17. #17

  18. #18
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Getting it all working is another matter eh? Can't bear to look at it anymore today. setting it aside for a few days. Need to think about game play and how to handle the cards. I imagine I'll use duplicateMovieClip on the one card I have and then attach a bitmap to each. Long way to go to a finished game.

  19. #19
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Yeah...I magine the math is getting heavy now. It's going to be a winner..no matter how long it takes. Seriously.... that is a beautiful stage.

  20. #20
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Quote Originally Posted by blanius
    Hey Wilbert, to use this for like a sprite sheet. Do I have to first load a image into a bitmapData object then load that into a movieclip and then copy the part I want to yet another bitmapData object to then copy out to display movieclip?
    Hey Bret, I'm not sure reading your other messages after this one means you figured it out or are using a more complex way.

    - first load the sprite sheet into a BitmapData object.
    - then create a new target bitmap image using new flash.display.BitmapData
    - use targetBitmap.copyPixels(spriteSheetBitmap,new flash.geom.Rectangle(sourceX,sourceY,width,height) ,new flash.geom.Point(0,0)) to copy the desired part to the target bitmap.
    - attach the target bitmap to a movieclip.

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