Ok guys, i’m loading a background from xml and i adapt it propotionally to the screen.
This is my class for handling all the things:
package
{
import flash.text.*;
import flash.display.*;
import flash.events.MouseEvent;
import flash.text.*;
import flash.utils.*;
import flash.net.*;
public class Main extends MovieClip
{
public function Main()
{
var strURL:String = "main.xml";
mcmenu.x = mcmenu.width / 2;
mcmenu.y = 43;
mcmenu.asd.company.text = "asdasd";
** stage.addEventListener(Event.RESIZE, sizeListener);**
mcmenu.addEventListener(MouseEvent.MOUSE_DOWN, Fullscreen);
loadxml(strURL);
}
private function Fullscreen(e:MouseEvent){
stage.displayState = StageDisplayState.FULL_SCREEN;
}
private function loadxml(stringaURL:String):void{
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, handleComplete);
loader.load(new URLRequest(stringaURL));
}
private function handleComplete(e:Event):void{
var myXML:XML = new XML(e.target.data);
var myURL:String = myXML.sfondo;
var sfondoURL:URLRequest = new URLRequest(myURL);
var loader:Loader = new Loader();
sfondo.addChild(loader);
** backgroundHandle();**
loader.load(sfondoURL);
}
**private function backgroundHandle(){
scaleProportional();
centerPic();
}
private function scaleProportional():void {
var picHeight = sfondo.height / sfondo.width;
var picWidth = sfondo.width / sfondo.height;
if ((stage.stageHeight / stage.stageWidth) < picHeight) {
sfondo.width = stage.stageWidth;
sfondo.height = picHeight * sfondo.width;
} else {
sfondo.height = stage.stageHeight;
sfondo.width = picWidth * sfondo.height;
}
}
private function centerPic():void {
sfondo.x = stage.stageWidth / 2;
sfondo.y = stage.stageHeight / 2;
}
private function sizeListener(e:Event){
scaleProportional();
centerPic();
}**
}
}
The bold lines handling the background.
The result is that if i add a comment to the bold lines so that it doesn’t run those lines, the script load the background and put it on the stage. but if i don’t comment this lines so that the script run those lines the result is that it does not load the background and i don’t see it.
Can someone help me? It’s very important…