Copy link to clipboard
Copied
I think this is very old question,
in as2 you can just add a external swf inside a mc. like this - loadMovie ("example.swf", "_root.mc"); and that's it.
how do i do that in as3? this following doesn't work..
var newLoader:Loader = new Loader();
function loadMc(evt:MouseEvent) {
var request:URLRequest = new URLRequest("example.swf");
newLoader.load(request);
addChild(mc.newLoader);
}
can I go remove mc first, and then add the swf as mc again?
removeChild(mc);
addChild(mc);
Copy link to clipboard
Copied
there's generally no reason to do that but, you can:
var newLoader:Loader = new Loader();
function loadMc(evt:MouseEvent) {
var request:URLRequest = new URLRequest("example.swf");
newLoader.load(request);
mc.addChild(newLoader);
}
Copy link to clipboard
Copied
Hi Kglad,
my 'mc' has another clip 'mc1' in it. so i tried to remove mc1 after loaded example.swf
I did try these method
#1
var newLoader:Loader = new Loader();
function loadMc(evt:MouseEvent) {
var request:URLRequest = new URLRequest("example.swf");
newLoader.load(request);
mc.addChild(newLoader);
mc.removeChild(mc1); <--
}
#2
var newLoader:Loader = new Loader();
function loadMc(evt:MouseEvent) {
var target = mc.mc1;
var request:URLRequest = new URLRequest("example.swf");
newLoader.load(request);
mc.addChild(newLoader);
removeChild(target); <--
}
both don't work, example.swf is added, but can't get rid of the original mc
you know in as2, when I call 'loadMovie ("example.swf", "_root.mc");', example.swf will just replace mc.
Copy link to clipboard
Copied
Look here how loading in AS3 works.
Important: You must always wait until your swf is fully loaded until you do any DisplayListManipulations (adding or emoving childs, accessing stage, root or parent) with it.
Use Event.COMPLETE for that.
Then move your lines
mc.addChild(newLoader);
mc.removeChild(mc1);
inside that Handler-function
Copy link to clipboard
Copied
Hi, moccamaximum,
thank you, going to test-fail-test for a while with this.
meanwhile Im gonna ask ahead another thing
Hi kglad, you gave me the source file for jpegTest yesterday, I tested it work like charm,
now you have these,
import JPEGEncoder;
var bmpd:BitmapData=new BitmapData(mc.width,mc.height);
bmpd.draw(mc);
var jpegEnc:JPEGEncoder = new JPEGEncoder(75);
var jpegDat:ByteArray = jpegEnc.encode(bmpd);
then in function localSave it send jpegDat to php for generating the jpeg.
I want to pack these into calling function, so after example.swf loaded into mc, can call the function so the jpegDat will have the data of example.swf and generate the jpeg from it?
jpgDatGenerate('mc');
function jpgDatGenerate (target) {
var bmpd:BitmapData=new BitmapData(target.width,target.height);
bmpd.draw(target);
var jpegEnc:JPEGEncoder = new JPEGEncoder(75);
var jpegDat:ByteArray = jpegEnc.encode(bmpd);
}
obviously something wrong, it gives me something about jpegDat not defined at localSave
what have I missed?
Copy link to clipboard
Copied
don't confound threads. keep the jpegencoder code in that thread.
as for removing mc1, if that's a child movieclip of mc, your code is fine. you don't need to wait until loading is complete to remove a child movieclip.
if you're trying to remove mc, then your code (and this thread) makes no sense. a loader is a displayobject and can be (and usually is) added to the displaylist without creating a holder movieclip (like mc) as its displayobjectcontainer.
if you're trying to remove some previously loaded swf, you can use the same loader (which can only load one swf/bitmap at any one time), or apply unload() (or better, unloadAndStop() ) to the loader and/or you can remove the loader just like any child.
Copy link to clipboard
Copied
hi, Kglad,
sorry about that , going to post jpegtest problem there
to conclude what I'm trying to do , you see in the jpegTest, you have the rainbow pic 'mc',
inside 'mc' i created a child clip 'mc1' to contain the rainbow,.
then in the content with the buttons I made a new button that would load the example.swf into 'mc' and replace the rainbow 'mc1'.
and then jpegDat should then contain dataByte of example.swf but not the rainbow.
still test-fail-testing for whatever i got so far.
Copy link to clipboard
Copied
var newLoader:Loader = new Loader();
function loadMc(evt:MouseEvent) {
var request:URLRequest = new URLRequest("example.swf");
newLoader.load(request);
mc.addChild(newLoader);
mc.removeChild(mc1); <--
}
it gives me undefined property mc1 , I do have mc1 inside 'mc'!! and that was why I tried this, to put mc.mc1 inside 'target', no error, but then in the swf it doesn't remove the rainbow either
#2
var newLoader:Loader = new Loader();
function loadMc(evt:MouseEvent) {
var target = mc.mc1;
var request:URLRequest = new URLRequest("example.swf");
newLoader.load(request);
mc.addChild(newLoader);
removeChild(target); <--
}
Copy link to clipboard
Copied
for moccamaximum,
I tried the methods with Event:COMPLETE, like these
pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
function imgLoaded(event:Event):void
{
mc.addChild(pictLdr.content);
//mc.removeChild(mc1.content); <-- doesn't work
}
it still do exact same thing like my code, mc1 still debugged undefined..
just what's wrong with this mc1, i kept opening mc to see if mc1 in it, it's right there!
Copy link to clipboard
Copied
hi all,
surprisingly, turns out this is the answer!
removeChild(mc.mc1); X
mc.removeChild(mc1); X
mc.removeChild(mc.mc1); !!! <-- this is really strange syntax if you ask me, but it does the job finally.
function loadMc(evt:MouseEvent) {
var request:URLRequest = new URLRequest("example.swf");
newLoader.load(request);
mc.addChild(newLoader);
mc.removeChild(mc.mc1); <--!!
}
Thank you again for all the helps!
Copy link to clipboard
Copied
hi kglad,
going to try that too, just in case, thanks a lot
Copy link to clipboard
Copied
no, don't botther.
if mc1 is not defined in the scope of the timeline that contains the code, you'll need to use:
mc.removeChild(mc.mc1)
Copy link to clipboard
Copied
replace
mc.removeChild(mc1);
with
MovieClip(mc).removeChild(mc1);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now