kbled
March 9th, 2010, 02:40 PM
Let me just start by saying this forum is awesome, over the past 3 years I've found nearly all of the answers to my AS questions without posting once... That streak ends today.:insomniac:
I'm building a site where the client is going to be able to upload various backgrounds which load depending on which tab they click on.
The class is BigBackground.as. It does the loading of the backgrounds, and then in the .fla I would like to manipulate these "BigBackgrounds" starting with the width. However, even though the width traces correctly from BigBackground.as, the width traces to 0 from the .fla file. I can access width from the class, but how can I access the width & height from the .fla??
Please Help!
Here is the .fla:
import BigBackground;
var bg:BigBackground = new BigBackground("bgs/bigView.swf",".swf");
or
var bg:BigBackground = new BigBackground("bgs/ice.jpg",".jpg");
addChild(bg);
trace(bg.width + " : " + bg.height);
Here is the BigBackground.as :
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.display.Graphics;
import flash.display.LoaderInfo;
import flash.errors.IOError;
import flash.events.IOErrorEvent;
public class BigBackground extends MovieClip{
private var filePath:String;
private var fileType:String;
private var bgLoader:Loader;
private var swfBg:MovieClip;
private var picBg:Sprite;
public function BigBackground(_filePath:String, _fileType:String):void{
filePath = _filePath;
fileType = _fileType;
w=_w;
h=_h;
init();
}
private function init():void{
if(fileType == ".jpg"){
picBg = new Sprite();
bgLoader = new Loader();
//bgLoader.contentLoaderInfo.addEventListener(Event. INIT, startLoad,false,0,true);
bgLoader.contentLoaderInfo.addEventListener(Event. COMPLETE, loadComplete, false, 0, true);
bgLoader.load(new URLRequest(filePath));
}else if(fileType == ".swf"){
swfBg = new MovieClip();
bgLoader = new Loader();
bgLoader.contentLoaderInfo.addEventListener(Event. COMPLETE, loadComplete, false, 0, true);
bgLoader.contentLoaderInfo.addEventListener(IOErro rEvent.IO_ERROR, onError, false,0, true);
bgLoader.load(new URLRequest(filePath));
}else{
trace("file type must be .jpg or .swf");
}
}
private function loadComplete(evt:Event):void{
if(fileType ==".jpg"){
var image:Bitmap = Bitmap(evt.target.content);
image.cacheAsBitmap = true;
image.smoothing = true;
addChildAt(picBg,0);
picBg.addChild(image);
trace(picBg.width);
}else if(fileType ==".swf"){
swfBg = MovieClip(evt.target.content);
var swfHolder:MovieClip = new MovieClip();
addChild(swfHolder);
swfHolder.addChild(swfBg);
trace(swfHolder.width);
}
bgLoader.contentLoaderInfo.removeEventListener(Eve nt.COMPLETE, loadComplete);
}
private function onError(evt:IOErrorEvent):void{
trace("error: "+ evt.target);
}
}
}
I'm building a site where the client is going to be able to upload various backgrounds which load depending on which tab they click on.
The class is BigBackground.as. It does the loading of the backgrounds, and then in the .fla I would like to manipulate these "BigBackgrounds" starting with the width. However, even though the width traces correctly from BigBackground.as, the width traces to 0 from the .fla file. I can access width from the class, but how can I access the width & height from the .fla??
Please Help!
Here is the .fla:
import BigBackground;
var bg:BigBackground = new BigBackground("bgs/bigView.swf",".swf");
or
var bg:BigBackground = new BigBackground("bgs/ice.jpg",".jpg");
addChild(bg);
trace(bg.width + " : " + bg.height);
Here is the BigBackground.as :
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.display.Graphics;
import flash.display.LoaderInfo;
import flash.errors.IOError;
import flash.events.IOErrorEvent;
public class BigBackground extends MovieClip{
private var filePath:String;
private var fileType:String;
private var bgLoader:Loader;
private var swfBg:MovieClip;
private var picBg:Sprite;
public function BigBackground(_filePath:String, _fileType:String):void{
filePath = _filePath;
fileType = _fileType;
w=_w;
h=_h;
init();
}
private function init():void{
if(fileType == ".jpg"){
picBg = new Sprite();
bgLoader = new Loader();
//bgLoader.contentLoaderInfo.addEventListener(Event. INIT, startLoad,false,0,true);
bgLoader.contentLoaderInfo.addEventListener(Event. COMPLETE, loadComplete, false, 0, true);
bgLoader.load(new URLRequest(filePath));
}else if(fileType == ".swf"){
swfBg = new MovieClip();
bgLoader = new Loader();
bgLoader.contentLoaderInfo.addEventListener(Event. COMPLETE, loadComplete, false, 0, true);
bgLoader.contentLoaderInfo.addEventListener(IOErro rEvent.IO_ERROR, onError, false,0, true);
bgLoader.load(new URLRequest(filePath));
}else{
trace("file type must be .jpg or .swf");
}
}
private function loadComplete(evt:Event):void{
if(fileType ==".jpg"){
var image:Bitmap = Bitmap(evt.target.content);
image.cacheAsBitmap = true;
image.smoothing = true;
addChildAt(picBg,0);
picBg.addChild(image);
trace(picBg.width);
}else if(fileType ==".swf"){
swfBg = MovieClip(evt.target.content);
var swfHolder:MovieClip = new MovieClip();
addChild(swfHolder);
swfHolder.addChild(swfBg);
trace(swfHolder.width);
}
bgLoader.contentLoaderInfo.removeEventListener(Eve nt.COMPLETE, loadComplete);
}
private function onError(evt:IOErrorEvent):void{
trace("error: "+ evt.target);
}
}
}