getDefinitionByName
- coln
-
coln
- Member since: Aug. 1, 2011
- Offline.
-
- Forum Stats
- Member
- Level 01
- Musician
I'm trying to load a class from an imported SWC file using getDefintionByName. The only problem is that the class name is not known until runtime and never once used in the SWF file.
Example:
// The value for name is retrieved at runtime from an external file
var reference:Class = getDefintionByName(name) as Class;
var mc:MovieClip = new reference();
I keep getting the "Error #1065: Variable ___ is not defined." error. I am not using FlashDevelop or Flex. Is there any way I can solve this without having to declare every single class in the SWC?
- MSGhero
-
MSGhero
- Member since: Dec. 15, 2010
- Offline.
-
- Forum Stats
- Supporter
- Level 16
- Game Developer
At 12/8/13 12:04 AM, coln wrote: I keep getting the "Error #1065: Variable ___ is not defined." error. I am not using FlashDevelop or Flex. Is there any way I can solve this without having to declare every single class in the SWC?
http://www.ryanwelcher.com/getdefinitionbyname/. I think that means you have to list out the classes, like the last lines of this.
- coln
-
coln
- Member since: Aug. 1, 2011
- Offline.
-
- Forum Stats
- Member
- Level 01
- Musician
At 12/8/13 12:35 AM, MSGhero wrote: http://www.ryanwelcher.com/getdefinitionbyname/. I think that means you have to list out the classes, like the last lines of this.
Drats. I was hoping to avoid that. Oh well
- kkots
-
kkots
- Member since: Apr. 16, 2013
- Offline.
-
- Forum Stats
- Supporter
- Level 10
- Blank Slate
In Flash, if you exported a MovieClip in first/second frame into a class, it would exist despite you not referencing it, in the SWF.
- milchreis
-
milchreis
- Member since: Jan. 11, 2008
- Offline.
-
- Forum Stats
- Member
- Level 26
- Programmer
At 12/8/13 12:04 AM, coln wrote: Flex
What compiler do you use then?
Take a look at the compiler option
include-libraries
according to: http://stackoverflow.com/questions/4103641/working-with-swcs-getdefinitionbyname-issue
- coln
-
coln
- Member since: Aug. 1, 2011
- Offline.
-
- Forum Stats
- Member
- Level 01
- Musician
At 12/8/13 06:16 AM, kkots wrote: In Flash, if you exported a MovieClip in first/second frame into a class, it would exist despite you not referencing it, in the SWF.
Yea, that's set up for every movieclip I have at the moment, especially since my SWF is only 1 frame long anyway. The problem is the compiler being efficient and un-including any object that isn't specifically referenced in the code. Of course I could just plop all the movieclips onto the stage in a hidden frame, but that's not going to do it for an imported SWC.
At 12/8/13 07:25 AM, milchreis wrote: What compiler do you use then?
Don't hate me, but I'm just using the Flash IDE. Since I have a mac, I can't run FlashDevelop, and I haven't really had the motivation to mess around with Flex by itself. So far this is the first problem I have run into using Flash.
- kkots
-
kkots
- Member since: Apr. 16, 2013
- Offline.
-
- Forum Stats
- Supporter
- Level 10
- Blank Slate
At 12/8/13 03:48 PM, coln wrote: Yea, that's set up for every movieclip I have at the moment
Sorry, failed to reproduce the error, with movie clips being exported on first frame. Under no settings does such a thing happen.
Here's the FLA.
- milchreis
-
milchreis
- Member since: Jan. 11, 2008
- Offline.
-
- Forum Stats
- Member
- Level 26
- Programmer
At 12/8/13 03:48 PM, coln wrote:At 12/8/13 07:25 AM, milchreis wrote: What compiler do you use then?Don't hate me, but I'm just using the Flash IDE.
Find out if it has the same compiler options.
- coln
-
coln
- Member since: Aug. 1, 2011
- Offline.
-
- Forum Stats
- Member
- Level 01
- Musician
At 12/8/13 04:13 PM, kkots wrote: Sorry, failed to reproduce the error, with movie clips being exported on first frame. Under no settings does such a thing happen.
This problem only occurs on the objects I import from a SWC. Every object in the main FLA file exports on the first frame as expected.
At 12/8/13 04:55 PM, milchreis wrote: Find out if it has the same compiler options.
Thanks for the link. I'm looking into that now.
- kkots
-
kkots
- Member since: Apr. 16, 2013
- Offline.
-
- Forum Stats
- Supporter
- Level 10
- Blank Slate
At 12/8/13 05:05 PM, coln wrote: This problem only occurs on the objects I import from a SWC.
You don't need an SWC if you're using Flash. Flash has everything in its Library. SWC is used only when you compile with FlashDevelop.
Where did you even get the SWC from, and why are you compelled to use it?
Why can't you directly reference the variables in the SWC? You're not sure about what it contains?

