-
Swf load/unload need help
Hello,
I newish to Flash, and am having some issues. I'm working on a presentation and want to load some external swfs files. In frame one I have links that take you to a new frame. Some of those frames only need to load/unload one swf file, which I have working fine. However I'm running into issues when there are multiple swfs that I'm trying to load into one movie clip box. I would love to only have one loader and one button that will remove what ever is contained in that box. Right now I have a loader for each swf and a button that will remove the loader. But I keep getting an Error 1120: Access of undefined property codeLoad. Can some one help me figure this out. Here is the code in as3 as I have it now.
Code:
var frontbox:container = new container();
frontbox.x= -825;
frontbox.y= -235;
this.addChild(frontbox);
medicalOfficeBACK.addEventListener(MouseEvent.CLICK, goToHome);
function goToHome(e:MouseEvent):void{
removeChild(frontbox);
gotoAndStop("mapHome");
}
backCODE.visible = false;
backADMIN.visible = false;
backTRANS.visible = false;
///////Set up add/remove of Code Game
code.addEventListener(MouseEvent.CLICK, playCode);
code.tabEnabled = true;
function playCode(e:MouseEvent):void{
backCODE.visible = true;
var codeLoad:Loader = new Loader();
frontbox.addChild(codeLoad);
codeLoad.load(new URLRequest("ASSETS/swfs/Coding.swf"));
}
backCODE.addEventListener(MouseEvent.CLICK, removeCODE);
function removeCODE(e:MouseEvent):void{
frontbox.removeChild(codeLoad);
backCODE.visible = false;
backADMIN.visible = false;
backTRANS.visible = false;
}
///////Set up add/remove of Transcriptioin
transcription.addEventListener(MouseEvent.CLICK, playTrans);
transcription.tabEnabled = true;
function playTrans(e:MouseEvent):void{
backTRANS.visible = true;
// var transLoad:Loader = new Loader();
// frontbox.addChild(transLoad);
// transLoad.load(new URLRequest("ASSETS/swfs/Trans.swf"));
}
backTRANS.addEventListener(MouseEvent.CLICK, removeTRANS);
function removeTRANS(e:MouseEvent):void{
// frontbox.removeChild(transLoad);
backCODE.visible = false;
backADMIN.visible = false;
backTRANS.visible = false;
}
///////Set up add/remove of Admin section
admin.addEventListener(MouseEvent.CLICK, playAdmin);
admin.tabEnabled = true;
function playAdmin(e:MouseEvent):void{
backADMIN.visible = true;
// var adminLoad:Loader = new Loader();
// frontbox.addChild(adminLoad);
// adminLoad.load(new URLRequest("ASSETS/swfs/Admin.swf"));
}
backADMIN.addEventListener(MouseEvent.CLICK, removeADMIN);
function removeADMIN(e:MouseEvent):void{
// frontbox.removeChild(adminLoad);
backCODE.visible = false;
backADMIN.visible = false;
backTRANS.visible = false;
}
-
So I was trying a new method of having a button in the external swf that would close itself, but it is giving me errors. I've tried both:
this.parent.removeChild(this);
DisplayObjectContainer(this.parent).removeChild(th is);
This is my error:
Error: Error #2069: The Loader class does not implement this method.
at Error$/throwError()
at flash.display::Loader/removeChild()
at CodeREMOVE_fla::MainTimeline/CloseCode()
I don't know what would be easier for someone to help me with. Can some one please help me before I loose all my hair.
-
Ok I got the external swf to unload using the ... well... unload method. Here is the updated code:
PHP Code:
code.addEventListener(MouseEvent.CLICK, playCode); code.tabEnabled = true;
var codeLoad:Loader = new Loader();
function playCode(e:MouseEvent):void{ backCODE.visible = true; frontbox.addChild(codeLoad); codeLoad.load(new URLRequest("ASSETS/swfs/Coding.swf")); }
backCODE.addEventListener(MouseEvent.CLICK, removeCODE);
function removeCODE(e:MouseEvent):void{ codeLoad.unload(); backCODE.visible = false; backADMIN.visible = false; backTRANS.visible = false; }
However, can some one still help with condensing the code to just have one loader that will load all the external swfs? Also does someone know how to get the external swf to unload itself? I really would like to know how to do that.
Thanks all : )
-
To test this, need to have a movie clip in the library, export linkage 'closebtn'.
And unless you change the elements in the array, need to have the two external files.
You'll need to add code for positioning of loaded objects...
Code:
var objArray:Array=["sampleB.png","sampleA.swf"];
code.addEventListener(MouseEvent.CLICK, playCode);
code.tabEnabled=true;
function playCode(e:MouseEvent):void {
backCODE.visible=true;
for (var i in objArray) {
var codeLoad:Loader = new Loader();
frontbox.addChild(codeLoad);
codeLoad.load(new URLRequest(objArray[i]));
codeLoad.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
}
}
function completeHandler(e:Event):void {
if (e.target.content is MovieClip) {
var myMC:MovieClip=MovieClip(e.target.content);
var btn:closeBtn = new closeBtn();
myMC.addChild(btn);
btn.addEventListener(MouseEvent.CLICK, unloadSWF);
} else if (e.target.content is DisplayObject) {
var myL:Loader=Loader(DisplayObject(e.target.content).parent);
myL.addEventListener(MouseEvent.CLICK, unloadPIC);
}
}
function unloadPIC(e:MouseEvent):void {
e.target.unload();
}
function unloadSWF(e:MouseEvent):void {
e.currentTarget.parent.parent.unloadAndStop();
}
backCODE.addEventListener(MouseEvent.CLICK, removeCODE);
function removeCODE(e:MouseEvent):void {
var num:int=frontbox.numChildren-1;
for (var i=num; i>=0; i--) {
if (frontbox.getChildAt(i) is Loader) {
Loader(frontbox.getChildAt(i)).unloadAndStop();
}
}
backCODE.visible=false;
backADMIN.visible=false;
backTRANS.visible=false;
}
Above code adds a button to click to unload the swf. What type of event did you want to use for the external swf to unload itself?
Last edited by dawsonk; 04-14-2010 at 12:34 PM.
-
hi dawsonk. Thanks for the help. However I am not understanding what your code is doing compared to mine. Let me explain what I am trying to do...
I have 3 swfs that will load when you click a button. When the swf loads, it loads on top of the buttons, so it needs to be unloaded before you can click the next button to load a diffrent swf file. I need to load the swfs into a container (I think) because this is just a sub section of the whole project. so when you click the "exit" button it removes the container and whatever the contents. I hope this makes sense. I can get it to work with coding everything out by hand, but I have several other sections to code, and would like a way to make as little typing as possible (plus I like being efficient : )...
So here is my latest code:
PHP Code:
var frontbox:container = new container();
frontbox.x= -825;
frontbox.y= -235;
this.addChild(frontbox);
medicalOfficeBACK.addEventListener(MouseEvent.CLICK, goToHome);
function goToHome(e:MouseEvent):void{
removeChild(frontbox);
gotoAndStop("mapHome");
}
backCODE.visible = false;
backADMIN.visible = false;
backTRANS.visible = false;
///////Set up add/remove of Code Game
code.addEventListener(MouseEvent.CLICK, playCode);
code.tabEnabled = true;
var codeLoad:Loader = new Loader();
function playCode(e:MouseEvent):void{
backCODE.visible = true;
frontbox.addChild(codeLoad);
codeLoad.load(new URLRequest("ASSETS/swfs/code.swf"));
}
backCODE.addEventListener(MouseEvent.CLICK, removeCODE);
function removeCODE(e:MouseEvent):void{
codeLoad.unload();
backCODE.visible = false;
}
///////Set up add/remove of Transcriptioin
transcription.addEventListener(MouseEvent.CLICK, playTrans);
transcription.tabEnabled = true;
var transLoad:Loader = new Loader();
function playTrans(e:MouseEvent):void{
backTRANS.visible = true;
frontbox.addChild(transLoad);
transLoad.load(new URLRequest("ASSETS/swfs/trans.swf"));
}
backTRANS.addEventListener(MouseEvent.CLICK, removeTRANS);
function removeTRANS(e:MouseEvent):void{
transLoad.unload();
backTRANS.visible = false;
}
///////Set up add/remove of Admin section
admin.addEventListener(MouseEvent.CLICK, playAdmin);
admin.tabEnabled = true;
var adminLoad:Loader = new Loader();
function playAdmin(e:MouseEvent):void{
backADMIN.visible = true;
frontbox.addChild(adminLoad);
adminLoad.load(new URLRequest("ASSETS/swfs/admin.swf"));
}
backADMIN.addEventListener(MouseEvent.CLICK, removeADMIN);
function removeADMIN(e:MouseEvent):void{
adminLoad.unload();
backADMIN.visible = false;
}
I tried to reduce the code using this way I found online:
PHP Code:
var frontbox:container = new container();
frontbox.x= -825;
frontbox.y= -235;
this.addChild(frontbox);
frontUnload.visible = false;
/////set up MASTER back button
medicalOfficeBACK.addEventListener(MouseEvent.CLICK, goToHome);
function goToHome(e:MouseEvent):void{
removeChild(frontbox);
gotoAndStop("mapHome");
}
//////Set up loader
var frontLoad:Loader = new Loader();
function goLoad(e:MouseEvent):void{
var newSWFRequest:URLRequest = new URLRequest("ASSETS/swfs/" + event.target.name + ".swf");
frontUnload.visible = true;
frontLoad.load(newSWFRequest);
frontbox.addChild(frontLoad);
}
///////Set up add/remove of Code Game
code.addEventListener(MouseEvent.CLICK, goLoad);
code.tabEnabled = true;
trans.addEventListener(MouseEvent.CLICK, goLoad);
trans.tabEnabled = true;
admin.addEventListener(MouseEvent.CLICK, goLoad);
admin.tabEnabled = true;
///////set up unload button
frontUnload.addEventListener(MouseEvent.CLICK, removeSWF);
function removeSWF(e:MouseEvent):void{
frontLoad.unload();
frontUnload.visible = false;
}
but it does not seem to work for me. It gives me the error 1120 Access of undefined property event. source: var newSWFRequest:URLRequest = new URLRequest("ASSETS/swfs/" + event.target.name + ".swf");
I am not sure how the array will work, because I don't want to load all swfs on the stage at once, but one at a time. Thanks for any help you can give.
I think I am giving up on having the swf remove itself. I basically wanted to have a button in the external swf file, that once clicked would remove itself, but I think how i have my file set up is not the most ideal for this situation.
Thanks!
-
Can someone please help. I keep trying different things, but they don't work.
Thanks = )
-
Code:
var frontbox:container = new container();
frontbox.x=-825;
frontbox.y=-235;
this.addChild(frontbox);
var myLoad:Loader = new Loader();
frontbox.addChild(myLoad);
/*function completeHandler(e:Event):void {
if (e.target.content is MovieClip) {
var myMC:MovieClip=MovieClip(e.target.content);
var btn:closeBtn = new closeBtn();
myMC.addChild(btn);
btn.addEventListener(MouseEvent.CLICK, removeSWF);
}
}*/
function loadSWF(e:MouseEvent):void {
frontUnload.visible=true;
myLoad.load(new URLRequest("ASSETS/swfs/"+e.currentTarget.name+".swf"));
/*myLoad.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);*/
}
function removeSWF(e:MouseEvent):void {
myLoad.unloadAndStop();
frontUnload.visible=false;
}
function goToHome(e:MouseEvent):void {
frontbox.removeChild(myLoad);
removeChild(frontbox);
gotoAndStop("mapHome");
}
medicalOfficeBACK.addEventListener(MouseEvent.CLICK, goToHome);
frontUnload.visible=false;
frontUnload.addEventListener(MouseEvent.CLICK, removeSWF);
code.addEventListener(MouseEvent.CLICK, loadSWF);
code.tabEnabled=true;
trans.addEventListener(MouseEvent.CLICK, loadSWF);
trans.tabEnabled=true;
admin.addEventListener(MouseEvent.CLICK, loadSWF);
admin.tabEnabled=true;
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|