|
|
|||||||
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member
Join Date: May 2007
Location: Poland
Posts: 65
|
[RESOLVED] getDefinitionByName - how does it actually work?
flash.utils.getDefinitionByName - how it is supposed to work?
I create a class definition in .as script, and save it in a file myClass.as: PHP Code:
PHP Code:
Code:
ReferenceError: Error #1065: Variable myClass is not defined. at global/flash.utils::getDefinitionByName() at test_fla::MainTimeline/test_fla::frame1() Could somebody explain what is the difference, why it doesn't fetch the classes defined in external as files and does fetch ones on Flash library? Is it possible to make the getDefinitionByName (or some other method) fetch a class from external AS file anyhow? P.S. The deeper reason of that post is the following problem: I want to create an instance of a class which name is a variable. So, let's say I have a navigation tool that allows to choose between page1, page2 and page3. The navigation tool returns just the number 1, 2 or 3. I have three classes: Page1, Page2 and Page3 and I want to create an instance object of one of those 3 classes, depending on the incoming navigation number. So when the number comes, I add it to the word "Page" and get the class name, ex. "Page2". Now I'd like to fetch the class definition of that name, to make an instance of it. For fetching the class definition I use the getDefinitionByName method. And as I said - if the classes Page1, Page2 and Page3 sit in the Flash library, this getDefinitionByName method works. But if create the Page1, Page2 and Page3 proper .as class definitions, the method getDefinitionByName fails and return the ReferenceError: Error #1065. Anybody knows why? Last edited by ampo_webdesign; 05-31-2007 at 06:36 PM. |
|
|
|
|
|
#2 |
|
Member
Join Date: Oct 2000
Posts: 93
|
It because myClass is not being compiled into your file. Just because you import a class doesnt mean it gets compiled. Flash will check for any usage of that class and only compile it if it finds any. It does this so that you wont have extra code compiled that never gets used.
In this case, you can see the difference by adding a reference to the class so that the compiler includes it: PHP Code:
PHP Code:
|
|
|
|
|
|
#3 |
|
Member
Join Date: May 2007
Location: Poland
Posts: 65
|
Jjcorreia, with that single innocent sweet line you helped mi a lot, thanks!
|
|
|
|
|
|
#4 |
|
Member
Join Date: Oct 2000
Posts: 93
|
No problem. Anytime
|
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|