PDA

View Full Version : How to draw this rectangle and load something in the middle of it.



ecptavares
May 23rd, 2008, 09:38 AM
Hi!
I am trying to make a web site (1024 x 768) and I want to make a rectangle that will fit part of the window and this rectangle has to have a dropshadow. I want to load an image centered inside this rectangle.

Look what I am doing so far and please tell me what is wrong with it.



package
{
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;

public class FNR extends MovieClip
{
var imgLoader : Loader;
var url : URLRequest;
var BackMC : MovieClip = new MovieClip();

public function FNR()
{
init();
}

private function init():void
{
drawBackGround();
loadFlyer();
}

private function drawBackGround():void
{
BackMC.graphics.lineStyle(1, 0x000000, 1);
BackMC.graphics.drawRect(0,0,550,400);
BackMC.graphics.endFill();
addChild(BackMC);
}

private function loadFlyer():void
{
imgLoader = new Loader();
url = new URLRequest("flyer.jpg");

imgLoader.x = 0;
imgLoader.y = 0;
imgLoader.load(url);
imgLoader.contentLoaderInfo.addEventListener(Event .OPEN, onFlyerOPEN);
imgLoader.contentLoaderInfo.addEventListener(Progr essEvent.PROGRESS, onFlyerPROGRESS);
imgLoader.contentLoaderInfo.addEventListener(Event .COMPLETE, onFlyerCOMPLETE);

imgLoader.load(url);
addChild(imgLoader);
}

private function onFlyerOPEN(event:Event):void
{
trace("opened");
}

private function onFlyerPROGRESS(event:ProgressEvent):void
{
trace("Loading...");
}

private function onFlyerCOMPLETE(event:Event):void
{
trace("Closed");
}
}
}


but the rectangle is not being drawn correctly and it is getting bigger than my resolution which is set to 1024x768.

What am I doing wrong?

I also need to put a dropshadow in this rectangle.

Felixz
May 23rd, 2008, 10:30 AM
Is ur stage set to NO_SCALE?

ecptavares
May 23rd, 2008, 10:37 AM
No!

johnlouis
May 23rd, 2008, 10:59 AM
are you viewing it in a browser?
coz if you are, and you are setting it to fill the whole window, the swf could be stretching.
try adding
stage.scaleMode = StageScaleMode.NO_SCALE;
in your init() function and
import flash.display.StageScaleMode;

amarghosh
May 24th, 2008, 03:13 AM
trace(stage.stageWidth);
trace(stage.stageHeight);

if these are giving 1024x768, then try:

stage.scaleMode = StageScaleMode.SHOW_ALL;
stage.align = StageAlign.TOP;

else correct them

Felixz
May 24th, 2008, 06:17 AM
stage.align=StageAlign.TOP_LEFT;