0

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);
    }

}

}

}
Gobi
  • 155
  • 1
  • 1
  • 14

2 Answers2

2

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()

James
  • 969
  • 1
  • 8
  • 13
0

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

alxx
  • 9,897
  • 4
  • 26
  • 41