Be a Supporter!

No Need To Import Dynamic Classes?

  • 221 Views
  • 4 Replies
New Topic Respond to this Topic
kylelyk
kylelyk
  • Member since: May. 15, 2008
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
No Need To Import Dynamic Classes? 2010-07-06 20:43:21 Reply

While I was reading an AS3 book, there was an example of a dynamic class. I know other classes can create new vars for the dynamic class at runtime, but somehow it doesn't need to be imported in order to be used in another classes.

EX: There are two classes: one called main and another dynamic class named card. Main can use card as if it had been imported but without importing it.

Any idea of how this works?


Kylelyk: Forwards and Backwards, Over and Out.

BBS Signature
Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to No Need To Import Dynamic Classes? 2010-07-06 20:51:41 Reply

I believe that if two classes are in the same package, they do not have to import one another. This is probably what you are experiencing.


#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

BBS Signature
kylelyk
kylelyk
  • Member since: May. 15, 2008
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to No Need To Import Dynamic Classes? 2010-07-06 20:54:50 Reply

By same package, do you mean same folder? Because they are in the same folder but not in the same .as file...


Kylelyk: Forwards and Backwards, Over and Out.

BBS Signature
Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to No Need To Import Dynamic Classes? 2010-07-06 21:05:10 Reply

By package I mean the package { } code that wraps around a class within a .as file.

eg:

package CustomPackage {
     // class
}

You use packages to group classes together. If two classes are in the same package, they can instantiate one another without importing.

If the name of a package is omitted

package {
     // class
}

It just sticks the class into a generic default package that all classes with unspecified packages go to.


#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

BBS Signature
Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to No Need To Import Dynamic Classes? 2010-07-06 21:06:59 Reply

Classes of the same package must be in a folder that is named that package, unless it is the default package, in which case it is in the same directory as the .fla file.

Also, you cannot have more than one class inside a .as file


#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

BBS Signature