Reputation: 155
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)
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
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.
Upvotes: 2
Reputation: 9897
Try this: 1. beginBitmapFill() 2. drawRect() 3. endFill() (never forget step 3!)
Upvotes: 0