nyghtrunner
01-14-2010, 08:25 AM
Hey all,
So I've run into something of an unusual problem, and I'm not exactly sure how to go about combatting it.
I'm writing a class that is meant to load a SWF that was published in Flex. Shouldn't be an issue, I've loaded lots and lots of SWFs before, but something is going amiss.
The load itself is working like a charm, but once everything is actually done loading, the instance of my class is returning some very odd values for the height/width. There are absolutely no graphics associated with this class that could increase the size somewhere, only the graphics from the imported SWF. Here is the code I have written so far:
package coms.manipulatives {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.events.ErrorEvent;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import coms.utils.hostHolder;
import gs.TweenLite;
import gs.easing.*;
public class BlackBox_Draggable extends Sprite {
private var _parameterObj:Object;
private var _bNeedsTitleBar:Boolean = false;
private var _draggablePath:String;
private var _bDragging:Boolean = false;
private var _loadClip:MovieClip;
public function BlackBox_Draggable() {
addEventListener(Event.ADDED_TO_STAGE,init);
}
//EVENT HANDLERS
private function init(e:Event):void {
loadDraggable();
removeEventListener(Event.ADDED_TO_STAGE,init);
}
private function loadDraggable():void {
var mcl:Loader = new Loader();
var loadURL:String = _draggablePath;
var req:URLRequest = new URLRequest(loadURL);
try {
mcl.load(req);
} catch (err:Error) {
trace("Unable to load: "+err);
}
mcl.contentLoaderInfo.addEventListener(Event.COMPL ETE,initImage);
mcl.contentLoaderInfo.addEventListener(ProgressEve nt.PROGRESS,initProgressHandler);
mcl.contentLoaderInfo.addEventListener(Event.INIT, initLoadHandler);
function initLoadHandler(e:Event):void {
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
var loadNum:Number = loaderInfo.bytesTotal;
}
function initProgressHandler(e:ProgressEvent):void {
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
var loaded:Number = loaderInfo.bytesLoaded;
var total:Number = loaderInfo.bytesTotal;
var pct:Number = loaded/total;
}
function initImage(e:Event):void {
_loadClip = MovieClip(mcl.content);
_loadClip.x = -_loadClip.height/2;
_loadClip.y = -_loadClip.width/2;
addChild(_loadClip);
mcl.contentLoaderInfo.removeEventListener(Event.CO MPLETE,initImage);
mcl.contentLoaderInfo.removeEventListener(Progress Event.PROGRESS,initProgressHandler);
mcl.contentLoaderInfo.removeEventListener(Event.IN IT,initLoadHandler);
if (!_bNeedsTitleBar) {
setDragHandlers();
}
}
}
private function dragMe(e:MouseEvent):void {
trace(_loadClip.width+": loadWidth"); //returns 500, which is the correct size of imported SWF
trace(_loadClip.height+": loadHeight");//returns 375, which is the correct size of the imported SWF
trace(this.width+": thisWidth");//returns 1024, which is the size of the stage...
trace(this.height+": thisHeight");//returns 768, which is the size of the stage...
var tempSprite:Object = this.parent;
hostHolder.Host.contentHolder.addChild(tempSprite) ;
tempSprite.startDrag(false);
_bDragging = true;
stage.addEventListener(MouseEvent.MOUSE_UP,stopDra ggingMe);
}
private function stopDraggingMe(e:MouseEvent):void {
var tempSprite:Object = this.parent;
tempSprite.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP,stop DraggingMe);
if (this.hitTestObject(hostHolder.Host.recycleBin)) {
hostHolder.Host.myHand.recycleMe();
}
}
//END EVENT HANDLERS
private function setDragHandlers():void {
_loadClip.addEventListener(MouseEvent.MOUSE_DOWN,d ragMe);
}
//GETTERS/SETTERS
public function set parameterObj(obj:Object):void {
_parameterObj = obj;
}
public function set bNeedsTitleBar(b:Boolean):void {
_bNeedsTitleBar = b;
}
public function set draggablePath(str:String):void {
_draggablePath = str;
}
//END GETTERS/SETTERS
}
}
And here is the constructor call:
var tile:BlackBox_Draggable = new BlackBox_Draggable();
var container:Sprite = new Sprite();
container.x = stage.mouseX;
container.y = stage.mouseY;
hostHolder.Host.contentHolder.addChild(container);
tile.parameterObj = _parameterObj;
tile.bNeedsTitleBar = _bNeedsTitleBar;
tile.draggablePath = _draggablePath;
container.addChild(tile);
The size of the imported SWF is 500x375. Outside of that, I cannot think of anything in this class that could possibly affect the dimensions of it. When I construct it, I do not set a height/width. I cannot see ANYTHING in this code that would make the size of the instance the size of the stage (1024x768), but for some reason, it is most definitely registering at that, making for some very... not good ordering issues with multiple objects on the screen, as now I have a hit area of more than double the size it is supposed to be...
So I was wondering... Could this have something to do with the SWF coming from Flex? Is there any way anyone can think of to combat this problem? I have access to the MXML files and Flex, so if it's a setting there, I can change it, but so far as I know, the size of the SWF coming from flex is 500x375. That information even traces correctly off the _loadClip properties. That makes me think somewhere in there, it's grabbing the stage dimensions.
So I've run into something of an unusual problem, and I'm not exactly sure how to go about combatting it.
I'm writing a class that is meant to load a SWF that was published in Flex. Shouldn't be an issue, I've loaded lots and lots of SWFs before, but something is going amiss.
The load itself is working like a charm, but once everything is actually done loading, the instance of my class is returning some very odd values for the height/width. There are absolutely no graphics associated with this class that could increase the size somewhere, only the graphics from the imported SWF. Here is the code I have written so far:
package coms.manipulatives {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.events.ErrorEvent;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import coms.utils.hostHolder;
import gs.TweenLite;
import gs.easing.*;
public class BlackBox_Draggable extends Sprite {
private var _parameterObj:Object;
private var _bNeedsTitleBar:Boolean = false;
private var _draggablePath:String;
private var _bDragging:Boolean = false;
private var _loadClip:MovieClip;
public function BlackBox_Draggable() {
addEventListener(Event.ADDED_TO_STAGE,init);
}
//EVENT HANDLERS
private function init(e:Event):void {
loadDraggable();
removeEventListener(Event.ADDED_TO_STAGE,init);
}
private function loadDraggable():void {
var mcl:Loader = new Loader();
var loadURL:String = _draggablePath;
var req:URLRequest = new URLRequest(loadURL);
try {
mcl.load(req);
} catch (err:Error) {
trace("Unable to load: "+err);
}
mcl.contentLoaderInfo.addEventListener(Event.COMPL ETE,initImage);
mcl.contentLoaderInfo.addEventListener(ProgressEve nt.PROGRESS,initProgressHandler);
mcl.contentLoaderInfo.addEventListener(Event.INIT, initLoadHandler);
function initLoadHandler(e:Event):void {
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
var loadNum:Number = loaderInfo.bytesTotal;
}
function initProgressHandler(e:ProgressEvent):void {
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
var loaded:Number = loaderInfo.bytesLoaded;
var total:Number = loaderInfo.bytesTotal;
var pct:Number = loaded/total;
}
function initImage(e:Event):void {
_loadClip = MovieClip(mcl.content);
_loadClip.x = -_loadClip.height/2;
_loadClip.y = -_loadClip.width/2;
addChild(_loadClip);
mcl.contentLoaderInfo.removeEventListener(Event.CO MPLETE,initImage);
mcl.contentLoaderInfo.removeEventListener(Progress Event.PROGRESS,initProgressHandler);
mcl.contentLoaderInfo.removeEventListener(Event.IN IT,initLoadHandler);
if (!_bNeedsTitleBar) {
setDragHandlers();
}
}
}
private function dragMe(e:MouseEvent):void {
trace(_loadClip.width+": loadWidth"); //returns 500, which is the correct size of imported SWF
trace(_loadClip.height+": loadHeight");//returns 375, which is the correct size of the imported SWF
trace(this.width+": thisWidth");//returns 1024, which is the size of the stage...
trace(this.height+": thisHeight");//returns 768, which is the size of the stage...
var tempSprite:Object = this.parent;
hostHolder.Host.contentHolder.addChild(tempSprite) ;
tempSprite.startDrag(false);
_bDragging = true;
stage.addEventListener(MouseEvent.MOUSE_UP,stopDra ggingMe);
}
private function stopDraggingMe(e:MouseEvent):void {
var tempSprite:Object = this.parent;
tempSprite.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP,stop DraggingMe);
if (this.hitTestObject(hostHolder.Host.recycleBin)) {
hostHolder.Host.myHand.recycleMe();
}
}
//END EVENT HANDLERS
private function setDragHandlers():void {
_loadClip.addEventListener(MouseEvent.MOUSE_DOWN,d ragMe);
}
//GETTERS/SETTERS
public function set parameterObj(obj:Object):void {
_parameterObj = obj;
}
public function set bNeedsTitleBar(b:Boolean):void {
_bNeedsTitleBar = b;
}
public function set draggablePath(str:String):void {
_draggablePath = str;
}
//END GETTERS/SETTERS
}
}
And here is the constructor call:
var tile:BlackBox_Draggable = new BlackBox_Draggable();
var container:Sprite = new Sprite();
container.x = stage.mouseX;
container.y = stage.mouseY;
hostHolder.Host.contentHolder.addChild(container);
tile.parameterObj = _parameterObj;
tile.bNeedsTitleBar = _bNeedsTitleBar;
tile.draggablePath = _draggablePath;
container.addChild(tile);
The size of the imported SWF is 500x375. Outside of that, I cannot think of anything in this class that could possibly affect the dimensions of it. When I construct it, I do not set a height/width. I cannot see ANYTHING in this code that would make the size of the instance the size of the stage (1024x768), but for some reason, it is most definitely registering at that, making for some very... not good ordering issues with multiple objects on the screen, as now I have a hit area of more than double the size it is supposed to be...
So I was wondering... Could this have something to do with the SWF coming from Flex? Is there any way anyone can think of to combat this problem? I have access to the MXML files and Flex, so if it's a setting there, I can change it, but so far as I know, the size of the SWF coming from flex is 500x375. That information even traces correctly off the _loadClip properties. That makes me think somewhere in there, it's grabbing the stage dimensions.