How to reference a bitmap?
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: How to reference a bitmap?

  1. #1
    Junior Member
    Join Date
    Aug 2004
    Posts
    12

    How to reference a bitmap?

    Hi

    I'm having problems removing a bitmap from the stage from within a function. Apparently I need to reference the bitmap first. How do I reference the following bitmap?

    The bitmap code I'm using:
    PHP Code:
    function ScreenShot():void {
        
    addChild(snapShot(LoadedCam)); 
        function 
    snapShot(mc:DisplayObject):Bitmap {
            var 
    m:Matrix = new Matrix(Flip,0,0,1,240,400);        
            var 
    TempPhoto:BitmapData = new BitmapData(480,800,true,0x00000000);
            
    TempPhoto.draw(LoadedCam,m);
            var 
    bmp:Bitmap = new Bitmap(TempPhoto);
            return 
    bmp;
        }

    And the function code I'm using:
    PHP Code:
    function RetakeButton(event:MouseEvent):void 
        
    TempPhoto.dispose();

    Thanks in advance!

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    Hi,

    although I'm not so good at AS3, I will try to help you anyways. When you place add a bitmap to a MovieClip, you can't control it anylonger (as a bitmap), or at least not in AS2 (I don't know about AS3, but it should be the same). Therefore, you will have to remove the actual movieclip which has the bitmap in it, in order to remove your snapshot bitmap. As for BitmapData.dispose(), that only frees the memory of the bitmap information stored in memory, in other words, it doesn't remove a bitmap object.

    If this is not accurate, as I have little experience in AS3, then any AS3 guru is welcome to correct me.

    Hope this helps
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Junior Member
    Join Date
    Aug 2004
    Posts
    12
    Thanks for your reply.

    What I'm trying to so is take a screen shot, then be able to reposition that screen shot then eventually remove the screen shot from the stage. So I need to somehow reference the bitmap in order to do so?

    Do I reference this with addChild and delete the bitmap off the stage using removeChild? If so, how do I create a reference to the bitmap?

    Any ideas?

    Cheers.

  4. #4
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    665
    you can't do TempPhoto.dispose(); because TempPhoto is local to snapShot. even if it was not, and you could, disposing it is only half of the job, you also need to remove it from display list.

    if you do not add anything else after the bitmap, it will be on top of display list:
    PHP Code:
    var bmp:Bitmap removeChildAt(numChildren 1) as Bitmap;
    bmp.bitmapData.dispose(); 
    how do I create a reference to the bitmap?
    you could go this way, too. for the reference to be available in other functions, you need to place it outside ScreenShot function:
    PHP Code:
    var reference:Bitmap;
    function 
    ScreenShot ():void {
        
    addChild(reference snapShot(LoadedCam)); 
    then in RetakeButton you could do just
    PHP Code:
    removeChild(reference);
    reference.bitmapData.dispose();
    reference null// send the reference to GC 
    Last edited by realMakc; 08-12-2013 at 07:28 AM.

  5. #5
    Junior Member
    Join Date
    Aug 2004
    Posts
    12
    Perfect! you just put that into perspective for me and it works.

    Thanks so much

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

Poll by Flashkit.com