This site is optimised for Firefox 2.0 or Internet Explorer 7.

ClassPath problem

ntwobike has no avatar
ntwobike
 
Post Count: 81
Joined: Sun Sep 21, 2008 3:10 pm
Location: Sri lanka
Flash Version: Adobe Flash CS3

ClassPath problem

Postby ntwobike on Wed Mar 11, 2009 5:09 am

i have 2 problems.
1.if i create a custom class say "MyClass.as" and i'm use that class in "movie.fla" file.
if both files in same folder.i can directly import it like "import MyClass;" and it is working better.i search on google "set classpath in actionscript 3.0" they says goto publish settings and do some thing.i want to know is that must or not because without that settings changes that file work better.

2.i want to set class path my folder structure is below

project-->flashfiles
project-->classfiles

project folder has two folders i want to import MyClass.as file it is in classfiles folder.my fla file in "flashfiles" folder
how can i set class path

import ..classfiles.MyClass....?

jschertz has no avatar
jschertz
 
Post Count: 8
Joined: Mon Mar 09, 2009 6:27 pm
Location: Chicago
Flash Version: Adobe Flash CS4

Re: ClassPath problem

Postby jschertz on Wed Mar 11, 2009 4:37 pm

You almost have it correct. The only reason you'd want to set classpaths via Actionscript 3.0 Settings is if you have class files that are not directly in the folder structure of your .fla file. This is true regarding the example folder structure you've given.

Since you're .fla is not on the same branch path of your class files you will need to set classpaths. I went ahead and set up a dummy project structure based on the example you gave us. I added a new classpath ".." which goes up one folder level (remember "." is the same level and ".." goes up one level). so now the classpath is set to the parent folder of flashfiles. Now when I want to import anything I just use the qualified folder structure and ClassName.

Here's my import statement after I set the classpath:

Code: Select all
import classfiles.MyClass


Alternatively, I could have set the classpath to "../classfiles" in which case the import statement would be:

Code: Select all
import MyClass


Here's some source for reference:
import_test.zip
(7.59 KiB) Downloaded 36 times


The main thing to remember is importing classes in Actionscript is pretty much the same as browsing the folder structure on your OS.

Also, one more thing to note. It's common in the development (Flash Dev) world to set up your *packages with a reverse domain structure (i.e. com.myDomain.so.on.and.so.fourth). Traditionally, at its most basic level, I set a project up like this:

*packages refer to a folder hierarchy that contains classes myFolder.subFolder.anotherSubFolderWithClassesInIt

ProjectFolder.zip
(12 KiB) Downloaded 31 times


Notice the main .fla file is in the same branch as the com folder that contains all of my packages that will contain class files so there's no need to set a classpath in the .fla. an import statement might look like this:

Code: Select all
import com.godsavethetween.core.utils.MyUtil


Hope this helps.
Follow me on twitter: @jschertz
or go to my site: God Save The Tween

ntwobike has no avatar
ntwobike
 
Post Count: 81
Joined: Sun Sep 21, 2008 3:10 pm
Location: Sri lanka
Flash Version: Adobe Flash CS3

Re: ClassPath problem

Postby ntwobike on Thu Mar 12, 2009 9:00 am

thanks .... it help to me...thanks boss


Return to Actionscript 3.0

Who is online

Users browsing this forum: Kirone and 3 guests