Hi, I want to load a image in a rectangle which i draw through action script. Is it possible?
I am using AS3. Please help.
loading image in rectangle in AS3
Page 1 of 14 Replies - 4153 Views - Last Post: 30 April 2009 - 11:21 PM
Replies To: loading image in rectangle in AS3
#2
Re: loading image in rectangle in AS3
Posted 30 April 2009 - 05:31 AM
You will need to make the rectangle, load the image to a movieclip (blank) and set the rectangle as a mask for the image. So that only the part of the image inside the rectangle can be seen. You could also try to scale the image down, but if the rectangle doesn't have the same proportions as the image it won't look right.
HTH
HTH
#3
Re: loading image in rectangle in AS3
Posted 30 April 2009 - 06:01 AM
BetaWar, on 30 Apr, 2009 - 04:31 AM, said:
You will need to make the rectangle, load the image to a movieclip (blank) and set the rectangle as a mask for the image. So that only the part of the image inside the rectangle can be seen. You could also try to scale the image down, but if the rectangle doesn't have the same proportions as the image it won't look right.
HTH
HTH
Thank you for reply. But i am still facing problem. Here is my code i have used to draw the rectangle. I want to load the image in this rectangle.
var w:Number= 30;
var h:Number=30;
var brd:Sprite = new Sprite();
this.addChild(brd);
brd.graphics.lineStyle(1,0);
brd.graphics.beginFill(0xCCCCCC);
brd.graphics.drawRect(0,0,w,h);
brd.graphics.endFill();
brd.x = 20;
brd.y =50;
var urlreq:URLRequest = new URLRequest("image4.jpg");
var url:URLLoader = new URLLoader(urlreq);
var picloader:Loader = new Loader();
url.addEventListener(Event.COMPLETE, getlist);
function getlist(evt:Event):void
{
picloader.contentLoaderInfo.addEventListener(Event.COMPLETE, gotpic)
picloader.load(urlreq);
url.removeEventListener(Event.COMPLETE, getlist);
}
function gotpic(evt:Event):void
{
var mm:Bitmap = new Bitmap();
mm = Bitmap(evt.target.content);
brd.addChild(mm);
mm.x = brd.x;
mm.y = brd.y;
//mm.mask(brd);
picloader.contentLoaderInfo.removeEventListener(Event.COMPLETE, gotpic)
}
Mod edit - Please
#4
Re: loading image in rectangle in AS3
Posted 30 April 2009 - 09:57 PM
ok, so basically... I think the best thing for this for speed and versatility reasons is to just use the UILoader. UILoader is VERY Simple as well. just drag a UILoader component on the stage and set it's instance name.... after this, all you have to do is set a couple properties. for instance.... if you gave the UILoader an instance name of "ImgLoader" the code would look like this i believe.
ImgLoader.x = 200; ImgLoader.y = 200; ImgLoader.width = 200; ImgLoader.height = 200; ImgLoader.source = (image path here)
#5
Re: loading image in rectangle in AS3
Posted 30 April 2009 - 11:21 PM
blake912, on 30 Apr, 2009 - 08:57 PM, said:
ok, so basically... I think the best thing for this for speed and versatility reasons is to just use the UILoader. UILoader is VERY Simple as well. just drag a UILoader component on the stage and set it's instance name.... after this, all you have to do is set a couple properties. for instance.... if you gave the UILoader an instance name of "ImgLoader" the code would look like this i believe.
ImgLoader.x = 200; ImgLoader.y = 200; ImgLoader.width = 200; ImgLoader.height = 200; ImgLoader.source = (image path here)
Hi blake912,
Thank you for ur reply. Can you tell me where to insert this code in my script?
I am not only lookinfg for loading image but I want it to be loaded in the sprite.
One more thing can you tell me i f I can fill image insteed of filling color in beginFill.
for example - brd.graphics.beginFill(0xCCCCCC);
can i use image insteed of 0xCCCCCC.
thanks .
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|