PDA

View Full Version : Instantiating Movieclip using AS 3.0


uli-b
02-22-2009, 09:53 AM
Hello everybody,

I am currently working on a flash project that consits of two different fla files. I would like to instantiate numerous instances of fla2 inside fla1 and hence tried the following but it didn't work:

inside fla1.fla:

var instance:fla2 = new fla2();
addChild(instance);

inside fla2.as:

public class fla2 extends MovieClip {

public function classic_memory_editor(){
super();
}
}

When I run the code above, an instance of fla2 is added to fla1. But the Problem is, that the contents of fla2.fla are not added to fla1 because fla2.as of course does not know about fla2.fla... hard to understand - I hope someone out there gets what I mean...

So how can I instantiate one flash file inside another?

Thanks and best regards,

Uli

rawmantick
02-22-2009, 10:22 AM
that the contents of fla2.fla are not added
Classes? Symbols? Only thing that are "exported for actionscript" are available... as I know...

uli-b
02-22-2009, 11:45 AM
So if I exported my FLash file fla2 for actionscript, how can I instantiate it from inside another flash file (fla1)?

Thanks

rawmantick
02-22-2009, 11:53 AM
You publish fla file, so the result is swf. SWF file can be loaded with Loader class (don't forget to addChild() the loader).

uli-b
02-22-2009, 12:03 PM
OK, but how can I then access the public methodes of the swf file?

var instance:fla2 = Loader(event.target.loader) as fla2;

does not work. Can you maybe give a sample?

Thanks for your help!

rawmantick
02-22-2009, 12:11 PM
loader.addEventListener(Event.COMPLETE,onComplete) ;
addChild(loader);
loader.load(new URLRequest("sdfsdfsdfsdfsdfsdfsdf"));

function onComplete(event:Event):void
{
var fla:FLA2DocumentClass = loader.content as FLA2DocumentClass;
fla.callYourMethod();
}

uli-b
02-22-2009, 04:44 PM
Ok, thanks - this is working for me. But now I am facing an other error:
When loading my application, I get the error "ReferenceError: Error #1056: Cannot create property myObject on classic_memory_editor."

myObject is the Instance Name of one of the symbols n the stage of my fla2 file. The error appears, when I try to cast the loaded fla2 file inside my fla1 file.

When I remove the instance name of "myobject", fla1 loads properly.

Why is that? any suggestions? Thanks so far...