AS3 Q
- Started
- Last post
- 19 Responses
- ornj0
This thread makes my head hurt. Are you saying you want to write a program that doesn't need to be compiled? Actionscript is no longer a script. Sorry buddy, you are dealing with a language now.
I would agree with the swc. I'm not sure what the issue is with external classes. What are you trying to achieve? Do you want to have a DisplayObject that is not typed ahead of time? If you are referencing a class that is not compiled in the swf how the program supposed to know what you are talking about?
I think you should rethink what you are trying to accomplish. Sounds like you are doing it wrong.
- Ancillary0
Hey Pony Boy I've tried to do this before, I ended up just doing what you suggested, create a bunch of conditional operators that look for the class name and then create it the old fashioned way.
I know this can be done the way you were attempting because I saw it once in the AS3 Cook Book, but I can't find it right now
- PonyBoy0
"If you are referencing a class that is not compiled in the swf how the program supposed to know what you are talking about?"
... I came to that realization a few posts above... ... just a 'duh' moment on my end... nothing more...
... go about your business... ... and thank you for your responses :)
- ukit0
- kpl0
have you looked into applicationDomain.getDefinition...
ie.
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEven... loadDone);
loader.load("swfWithNewClasses.s...function loadDone(e:Event):void {
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
var NewClass:Class = loaderInfo.applicationDomain.get...
var mc:MovieClip = new NewClass() as MovieClip;
addChild(mc);
}
- kpl0
var loader:Loader = new Loader(); loader.contentLoaderInfo.addEven... loadDone);
loader.load("swfWithNewClasses.s...function loadDone(e:Event):void {
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
var NewClass:Class = loaderInfo.applicationDomain.get...
var mc:MovieClip = new NewClass() as MovieClip;
addChild(mc);
}
- kpl0
loaderInfo.
applicationDomain.
getDefinition("NewClassInSWF");returns the class object NewClassInSWF that is in the loaded swf.
- acescence0
in answer to your question about good tech forums..
- PonyBoy0
btw - given this forum is more design-oriented than dev-oriented... ... anyone of you Flash Dev's have another tech-related forum where you like to ask these Q's and get well-rounded answers / info?
- This place may not have a lot of devs percentage-wise, but the quantity of people will get you responses fast.CyBrain
- When I search for answers like this I find blogs that are years old.CyBrain
- yeah - I've found a few references to what I'm trying to do... but it's hard to say what the right search words arePonyBoy
- I've tried:
'as3 convert string text to class name' ... and only found so much infoPonyBoy
- ifeltdave0
I'm not sure, never tried what you're doing before. But places to look into are whether or not your external classes are public or private, what they extend (MovieClip, etc) and whether or not they are static or dynamic classes.
I think that if you associate a library clip with a class, it automatically extends as MovieClip, which is a dynamic class by default. Try making all your external classes dynamic, see where that leads.
- PonyBoy0
dave!... I've actually gone through all that - verified my classes are public and they all extend MovieClip... ... not static either...
... still getting:
"ReferenceError: Error #1065: Variable StringNamePassed is not defined."I looked up 1065... and it seems it's related to what you've mentioned - public vs. private... ...but not a whole lot more information...
- ifeltdave0
This is a stab in the dark, but try this:
When instantiating an external class, pass in as a string not only the class name but the path to it as well in your scripts folder.
Example:
updateMainContent( com.myScripts.ClassName );
- ifeltdave0
And also, not sure if you tried the dynamic thing, but :
public dynamic class MyExternalClass { ... etc
- SteveJobs0
the problem is that the compiler isn't seeing the class you are wanting to add dynamically.
here's proof
add this line before that function call:
var myClassReference:MyClassThatIWan...it will work then, because the compiler included it. just create a dummy reference to any class you could want to instantiate and include it in any module you need this functionality in.
- SteveJobs0
//comment/uncomment for amazing effects!!11
var dummyRef:com.Class1;var classRef:Class =
getDefinitionByName("com.Class1... as Class;
var obj:Object = new classRef();
addChild(DisplayObject(obj));- jebus..
http://pastebin.com/…SteveJobs - *trying this now!PonyBoy
- jebus..
- PonyBoy0
^^ that still requires I declare a class somewhere up front though... right?... I was trying to avoid that all-together and just add a new class...
... buttttttt... wait a sec... I still have to compile everytime I add a new class anyway...
... grr. :)
- PonyBoy0
*sigh... I'm just gonna write a switch statement that checks the name of the string and loads the appropriate class the old fashion way... getting behind on this project now :(
- SteveJobs0
well yeah dog, that's the way the flash compiler (and many others) works to keep the footprint small.
what you would do is just use an include directive which would point to a file containing all these dummy instantiations.
or just scrap it all and do it in html5 yo!!! (i keed, i keed)
- thatblokemike0
look into using a swc, closest to achieving what your after.
- also a good old fashioned 'include' should still work for embedding classesthatblokemike
- *looking into thisPonyBoy