View Full Version : [Rant] - Setting up classes
Digitalosophy
March 11th, 2008, 11:10 AM
I've never worked with classes. The only time I did was when I took a java course back in 01' in college. I purchased colin's AS 3.0 book, and I'm trying to pick it up - it's not that hard but...
He doesn't go into how to actually get this stuff to compile. For example, he gives tons f example source class' which is fine and dandy. But when I try to import this stuff there is no clear direction within the book.
Now Orth and batle were very patient with me in a previous thread and shed some light.
My question is where can I find a tutorial that will explain exactly what I need to do to get my classes to compile correctly. I'm not sure why I am finding this so difficult, I've been using action script for years now (professionally).
Any helpers?
dzhedzho
March 11th, 2008, 11:16 AM
I've never worked with classes. The only time I did was when I took a java course back in 01' in college. I purchased colin's AS 3.0 book, and I'm trying to pick it up - it's not that hard but...
He doesn't go into how to actually get this stuff to compile. For example, he gives tons f example source class' which is fine and dandy. But when I try to import this stuff there is no clear direction within the book.
Now Orth and batle were very patient with me in a previous thread and shed some light.
My question is where can I find a tutorial that will explain exactly what I need to do to get my classes to compile correctly. I'm not sure why I am finding this so difficult, I've been using action script for years now (professionally).
Any helpers?
What is actually the compile problem you are getting?
Compiler can't find where the classes are or?
Gundark
March 11th, 2008, 11:31 AM
Have you looked at Senocular's tutorial on AS3 in the Flash IDE?
http://www.senocular.com/flash/tutorials/as3withflashcs3/
It's not finished but it does have some stuff on getting classes and other stuff working.
Are the example classes you are using expecting to be the document class maybe? Instead of importing them onto your main timeline, have you tried setting the class as your document class?
Digitalosophy
March 11th, 2008, 03:42 PM
It's the set up that's a problem, actually trying to wrap my head around the whole class idea is the issue.
I took a step back and tryed doing a "Hello World" class.
Right now my directories are set up as follows..
com/digitalosophy/helloWorld/HelloWorld.as - this is my class file that resides where my other Flash classes are.
i.e. Applications/Adobe Flash CS3/Configuration/Classes - mac based...
HelloWorld.as
package com.digitalosophy.helloWorld {
public class HelloWorld {
public function HelloWorld() {
trace("Hello World");
}
}
}
On my main timeline i.e. HelloWorld.fla
import helloWorld.HelloWorld.*;
var myHelloWorld:HelloWorld = new HelloWorld();
The compile error I get is helloWorld.HelloWorld Definition cannot be found.
What the heck?
Digitalosophy
March 11th, 2008, 04:05 PM
This is complete and utter crap. If I put the .as file inside the folder with the .fla
and (I realized I needed to and change my code to this_
package {
public class HelloWorld {
public function HelloWorld() {
trace("Hello World");
}
}
}
It works. So I'm not sure how I screwed up the other way (with the class in another directory).
So strange.
Anogar
March 11th, 2008, 04:14 PM
You actually don't need to import it. Since you have it in the same directory, your code of:
ActionScript Code:
var myHelloWorld:HelloWorld = new HelloWorld()
... is calling the class called HelloWorld, which has the file name of HelloWorld.as - so that import is unnecessary, and perhaps not actually doing anything.
Now, the easy way to do it, which leaves you with no code on your timeline (yay) is to just type "HelloWorld" into the Document class box - which is on the 'properties' panel, same place you find the swf size and background and such. This sets up HelloWorld.as to be compiled with your SWF every time, and is the ideal way to make something your main class.
http://img98.imageshack.us/img98/7632/dcuj0.jpg
Fill in that empty "Document class" box. Don't put ".as" - just the name. :)
dzhedzho
March 11th, 2008, 04:17 PM
Don't be so upset, when importing, you got to include the package name. The package name should be same as the location of the as file. For your case
for the whole package
import com.digitalosophy.helloWorld.*;
for the class
import com.digitalosophy.helloWorld.HelloWord;
Digitalosophy
March 11th, 2008, 04:27 PM
@Anogar - thanks man good stuff.
@dz - I actally went down that road before (and after reading your post). This is what I'm not getting, my import call was actually what you suggested..
import com.digitalosophy.helloWorld.HelloWord;
And it still can't find it. I'm thinking the package name is conflicting with the timeline code at this point.
If I use the above code, then what should I declare inside my package?
package com.digitalosophy.helloWorld { // like right here is where the problem is I think
public class HelloWorld {
public function HelloWorld() {
trace("Hello World");
}
}
}
Thanks again guys, I am actually starting to understand how this works..
dzhedzho
March 11th, 2008, 05:23 PM
Well you should have the action script file in
something/com/digitalosophy/helloWorld
and the fla file should be in /something
then your timeline code should be something like
import com.digitalosophy.helloWorld.HelloWord;
var helou:HelloWorld = new HelloWorld();
nothing more
Ordinathorreur
March 11th, 2008, 07:02 PM
import com.digitalosophy.helloWorld.HelloWord;
That error was probably just a typo, should have been HelloWorld instead of HelloWord ;)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.