Gobi
Gobi

Reputation: 155

beginBitmapFill() is not working for existing movieclip, help me

I want to fill the image to the movie clip using beginBitmapFill(), but I don't see the image. Actually, I have created a movie clip with box and I skewed it. I want to show the image inside the skewed box. And Image also should look skewed (needs to fill inside the box)

enter image description here

Here is my action script code :

package{

import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event; 
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.LoaderInfo;

public class AttachMovieClipExample extends Sprite{

public var rect:MovieClip;

public function AttachMovieClipExample()
{
    rect = new redRectangle();

    var bitmapData:BitmapData;

    var loader:Loader = new Loader();
    loader.load(new URLRequest("sam.jpg"));
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);


    function onComplete (event:Event):void
    {
        bitmapData = Bitmap(LoaderInfo(event.target).content).bitmapData;
        rect.graphics.clear();
        rect.graphics.beginBitmapFill(bitmapData,null,false,true);
       // rect.graphics.endFill();
        rect.x = 400;
        rect.y = 210;
        addChild(rect);
    }

}

}

}

Upvotes: 0

Views: 868

Answers (2)

James
James

Reputation: 979

In your onComplete method you are missing the call to drawRect

function onComplete (event:Event):void
{

    bitmapData = Bitmap(LoaderInfo(event.target).content).bitmapData;
    rect.graphics.clear();
    rect.graphics.beginBitmapFill(bitmapData,null,false,true);
    rect.graphics.drawRect(x,y,height,width) //where x, y, height and width are values
    rect.graphics.endFill();
    rect.x = 400;
    rect.y = 210;
    addChild(rect);
}

The docs for the graphics class give you more information.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html#drawRect()

Upvotes: 2

alxx
alxx

Reputation: 9897

Try this: 1. beginBitmapFill() 2. drawRect() 3. endFill() (never forget step 3!)

Upvotes: 0

Related Questions