4 Replies - 5217 Views - Last Post: 30 April 2009 - 11:21 PM

#1 raajesh  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 21-November 08

loading image in rectangle in AS3

Post icon  Posted 29 April 2009 - 11:04 PM

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.
Is This A Good Question/Topic? 0
  • +

Replies To: loading image in rectangle in AS3

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1138
  • View blog
  • Posts: 7,110
  • Joined: 07-September 06

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
Was This Post Helpful? 0
  • +
  • -

#3 raajesh  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 21-November 08

Re: loading image in rectangle in AS3

Posted 30 April 2009 - 06:01 AM

View PostBetaWar, 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



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 :code:
Was This Post Helpful? 0
  • +
  • -

#4 blake912  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 18
  • Joined: 15-April 09

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)



Was This Post Helpful? 0
  • +
  • -

#5 raajesh  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 21-November 08

Re: loading image in rectangle in AS3

Posted 30 April 2009 - 11:21 PM

View Postblake912, 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 .
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1