Skip to main content
El_Arcon
Inspiring
August 25, 2010
Question

width/height/x/y value mismatch with the reality and what is coded

  • August 25, 2010
  • 1 reply
  • 2989 views

hello there everyone,

hope i got the title right..,

so here goes the problem i need your opinion and help to solve:

application definition:

i have this desktop flash application that will go fullscreen what this application do is loading external asset (mostlySWF) and play it inside this application. Each external asset will be place inside a container/holder (empty movie clip created by code), each of this container have it's own dimension ( width, height, x, y).my code all working without any warning nor error.oh and i also have an image.jpg/png as it's background and place at the bottom of display list (depth = 0), the image is customly made with using photoshop and each container location and dimension also measured there so it just needed to be writen down is the XML file..,

the problem:

the bug is when i loaded some image of those background image each container width,height,x,y  will mismatch with what i have in the XML file.

the funny thing is when i trace the value of each container width,height,x,y it value is the same with what the XML has yet by seeing with eye you know that is wrong..,

here's the code i used:

var myXML:XML; //to hold the loaded xml file
var SWFList:XMLList; //used to hold a list of all external swf source,atribute and etc
var xmlLoader:URLLoader = new URLLoader(); //intance of URLloader class used to XML file

var totalSWF:int; //hold the total number of external swf there is to be loaded
var mainContainer:MovieClip =new MovieClip();//act as the main container
var SWFContainer:MovieClip; //hold the loaded SWF as it's child
var swfLoader:Loader; //instance of loader class used to load the external swf
var myCounter:int = 0; //used to track how many external swf has been loaded and added to stage

var bgImageURL:String;//hold the url of the background image
var imageLoader:Loader;//intance of loader class used to load background image

// Stage Setting
//========================================================================================
this.stage.align = StageAlign.TOP_LEFT;
this.stage.scaleMode = StageScaleMode.NO_SCALE ;
this.stage.displayState = StageDisplayState.FULL_SCREEN;

//load the xml file
//==========================================================================================
xmlLoader.load(new URLRequest("FlashBlock.xml"));
xmlLoader.addEventListener(Event.COMPLETE, processXML);

function processXML(e:Event):void
{
    e.target.removeEventListener(Event.COMPLETE , processXML);
    myXML = new XML(e.target.data);
    bgImageURL = myXML.Background.text();
   
    SWFList = myXML.BLOCK;
    totalSWF = myXML.BLOCK.length();   
   
    doSizeUpMainContainer();
    loadBackgroundImage();
}

function doSizeUpMainContainer():void
{
    //resizing the mainContainer dimension
    //in this case i just make the size the same as the screen dimension
    addChild(mainContainer);
    mainContainer.graphics.beginFill(0xFD562D, 0);
    mainContainer.graphics.drawRect(0,0, stage.stageWidth, stage.stageHeight);
    mainContainer.graphics.endFill();
}

function loadBackgroundImage():void
{
    //load the background image
    imageLoader = new Loader();
    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onBgImageLoadComplete);
    imageLoader.load(new URLRequest(bgImageURL));
}

function onBgImageLoadComplete(e:Event):void
{
    e.target.removeEventListener(Event.COMPLETE, onBgImageLoadComplete);
   
    mainContainer.addChild(imageLoader.content);
    imageLoader.x = (stage.stageWidth - imageLoader.content.width)/2;
    imageLoader.y = (stage.stageHeight - imageLoader.content.height)/2;
   
    loadSWF();
}

function loadSWF():void
{
    swfLoader = new Loader();
    swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE , swfSetting);
    swfLoader.load(new URLRequest(SWFList[myCounter].@source));
}

function swfSetting(e:Event):void
{
    e.target.removeEventListener(Event.COMPLETE , swfSetting);
   
   SWFContainer = new MovieClip();
    mainContainer.addChild(SWFContainer);

    // i did this so i can resize the movieclip size to what i need..,
    SWFContainer.graphics.beginFill(0xff6633, 0);
    SWFContainer.graphics.drawRect(0,0, Number(SWFList[myCounter].@width), Number(SWFList[myCounter].@height));
    SWFContainer.graphics.endFill();
       
    SWFContainer.x = SWFList[myCounter].@left;
    SWFContainer.y = SWFList[myCounter].@top;
   
    SWFContainer.addChild(e.target.content);

    //load and add another SWFContainer untill all swf listed in the swf added
    if(myCounter < (totalSWF-1))
    {
        myCounter++;
        swfLoader = null;
        loadSWF();
    }
}

i really do not have any idea why this could happen and how to solve it..,

any help would be greatly apprecited cause i'm literally meeting a dead end with this bug..,

This topic has been closed for replies.

1 reply

Inspiring
August 25, 2010

x/y are relative to PARENT.


El_Arcon
El_ArconAuthor
Inspiring
August 25, 2010

hi there Andrei1 thanks for your response,

so there is might a chance that the image background is  stretched therefor all the value i used is messed with the one that is  stretched??

if yes how do i handle it and how do i correct this bug??

Inspiring
August 25, 2010

I don't see anything in your code that causes it. I suspect that some containers that are already on stage are scaled somehow. Make sure that they are not scaled before you add any children - scaling propagates to the children.