PDA

View Full Version : Loading swf's errors



waverider303
May 2nd, 2009, 02:11 PM
Im making a main page that will load different content into one loader. I have the loading URLRequest calling a variable for the link and then on a certain button click it will change the swf to be loading. The problem is this:
This code is being called in a movieclip inside the main timeline called "loaderHolder"

//I have all the variables initiated above these functions
function startLoad()
{
trace("Started");
mRequest = new URLRequest(MovieClip(root).loadContent);
trace(MovieClip(root).loadContent);
mLoader.load(mRequest);
}// end function

function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = Math.round((mProgress.bytesLoaded / mProgress.bytesTotal)*100);
load_txt.text = percent + "%";
load_txt.setTextFormat(LF_txt);
}// end function

function onCompleteHandler(loadEvent:Event)
{
loadContent_mc.addChild(loadEvent.currentTarget.co ntent);
removeChildAt(2);
removeChildAt(1);
}// end function


This is on the main timeline. These functions trigger a tween that will drop then comeback (yoyo) with new content to load.


//Tween/Start Loader
// Working to get tween to run then pop back with new content
var loadLoaderTween:Tween = new Tween(loaderHolder, "y", Strong.easeInOut, 1191.0, stage.stageHeight/2, 2, true);
loadLoaderTween.addEventListener(TweenEvent.MOTION _STOP, startLoading);
//This initiates the very first load
function startLoading(e:TweenEvent) {
this.loaderHolder.startLoad();
}

//Unload Current - Triggers on a button click
function unLoad() {
loadLoaderTween = new Tween(loaderHolder, "y", Strong.easeInOut, loaderHolder.y, 1191.0, 2, true);
loadLoaderTween.addEventListener(TweenEvent.MOTION _STOP, startNewLoad);
this.loaderHolder.mLoader.close();
}
function startNewLoad(e:TweenEvent) {
loadLoaderTween.removeEventListener(TweenEvent.MOT ION_STOP, startNewLoad);
loadLoaderTween.yoyo();
trace("Works");
loadContent = "/flash/test2.swf";
this.loaderHolder.startLoad();
}


I get these errors:


Error: Error #2029: This URLStream object does not have a stream opened.
at flash.display::Loader/close()
at csteelmedia_fla::MainTimeline/unLoad()
at csteelmedia_fla::btn_web_8/clicked()




//This one happens at this point: mLoader.load(mRequest);
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::Loader/_load()
at flash.display::Loader/load()
at csteelmedia_fla::mc_loaderHolder_1/startLoad()
at csteelmedia_fla::MainTimeline/startNewLoad()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at fl.transitions::Tween/stop()
at fl.transitions::Tween/set time()
at fl.transitions::Tween/nextFrame()
at fl.transitions::Tween/onEnterFrame()

wvxvw
May 2nd, 2009, 02:37 PM
loadContent_mc.addChild(loadEvent.currentTarget.co ntent);
You shouldn't reparent Loader's content. If it's a picture, it'll became a Bitmap, you can than grab it's bitmapdata and use it elsewhere. If it's an SWF, you can then reuse loaderInfo.bytes in combination with Loader#loadBytes().
This is also considered a good practice because technically you can reparent loader's content, but once you do so, you cannot call Loader#unload() or load other content with it. It's also easier to add the entire Loader to the display list than try to separate it from it's content. I'd better stick to that latter idea as it less troublesome.
Besides, your functions are missing return type.

waverider303
May 2nd, 2009, 03:07 PM
loadContent_mc.addChild(loadEvent.currentTarget.co ntent);
You shouldn't reparent Loader's content. If it's a picture, it'll became a Bitmap, you can than grab it's bitmapdata and use it elsewhere. If it's an SWF, you can then reuse loaderInfo.bytes in combination with Loader#loadBytes().
This is also considered a good practice because technically you can reparent loader's content, but once you do so, you cannot call Loader#unload() or load other content with it. It's also easier to add the entire Loader to the display list than try to separate it from it's content. I'd better stick to that latter idea as it less troublesome.
Besides, your functions are missing return type.

OK so I will give your code above a try. What should my return types be. I am a ok flash coder and still trying to learn but I never know when to use return;

wvxvw
May 2nd, 2009, 03:36 PM
If function doesn't return anything you type it to "void". Eg.:

function f():void {};