RE: [Flashcoders] import own class (use SOME_CONST instead ofMyUtils.SOME_CONST)

2007-04-04 Thread Jesse Graupmann
The problem is that those properties are in another Class, and that's how
you have to reference them. You do have a few choices.




//
//  VAR
//

The first is probably NOT what you want to hear - make a variable for each
of the constants.

import com.project.MyClass
var CONSTANT = MyClass.some_CONSTANT;
trace( CONSTANT );


//
//  IMPORT
//

The second is the most obvious and something you've already done - resolve
the path with import. Import really only gets rid of the directories in dot
notation form so you can call it by name and not have to use the path.

Without import:
trace( com.project.MyClass.some_CONSTANT )

With import:
import com.project.MyClass.some_CONSTANT
trace( MyClass.some_CONSTANT )


//
//  INCLUDE
//


The third is to define the variables before hand in a separate .as file and
include them ( like the VAR example above). This is really just a way of
compartmentalizing the code and doesn't really solve the issue. You're just
storing part of your code in another file and it's including that code when
it runs - I a lot like html includes.


In classInclude.as:
import com.project.MyClass;
var CONSTANT = MyClass.some_CONSTANT;


in OtherClass.as:
#include classInclude.as
trace( CONSTANT )



//
//  COPY
//


The forth is to copy the properties from one Class to another. But this is
obviously not the best way to go for a number of reasons.

import com.project.MyClass
for ( var prop in MyClass ) 
{
this [ prop ] = myClass[ prop ];
}



//
//  GETTERS / SETTERS
//

The fifth adds a little bulk in the beginning, but let's you retrieve
variables in a more condensed way using getters and setters - my favorite.

// VER 1 - AS 1.0 approach

import com.project.MyClass
function getCONSTANT (){ return MyClass.some_CONSTANT };
this.addProperty ('CONSTANT', getCONSTANT, null ); // set getter / setter
trace( CONSTANT ) 


// VER 2 - AS 2.0 approach

import com.project.MyClass
public function get CONSTANT (){ return MyClass.some_CONSTANT }
public function myFunction(){   trace( CONSTANT ) }




_

Jesse Graupmann
www.jessegraupmann.com 
www.justgooddesign.com/blog/  
_



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Alexander
Farber
Sent: Wednesday, April 04, 2007 12:41 AM
To: Flashcoders mailing list
Subject: [Flashcoders] import own class (use SOME_CONST instead
ofMyUtils.SOME_CONST)

Hi,

I'd like to move few constants and functions my project is using
into a separate class, called Util. How could I please make them
importable, i.e. so that I could write just

   import Util;
   trace(SOME_CONSTANT);

instead of always prepending Util. in front of the variables:

   trace(Util.SOME_CONSTANT)

I can't find it in the Flash help... Thank you

Also I wonder if I can run some function on the import statement
or do I have to always call Util.init_my_static_vars() manually?

Regards
Alex

-- 
http://preferans.de

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] import own class (use SOME_CONST instead ofMyUtils.SOME_CONST)

2007-04-04 Thread Adrian Lynch
Short of someone giving you a better answer, I'd say no. Unless you write
something that took a class and put all it's static members in the current
scope.

Best to wait till someone else answers this though, I'm just guessing :)

Adrian

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Alexander
Farber
Sent: 04 April 2007 08:41
To: Flashcoders mailing list
Subject: [Flashcoders] import own class (use SOME_CONST instead
ofMyUtils.SOME_CONST)


Hi,

I'd like to move few constants and functions my project is using
into a separate class, called Util. How could I please make them
importable, i.e. so that I could write just

   import Util;
   trace(SOME_CONSTANT);

instead of always prepending Util. in front of the variables:

   trace(Util.SOME_CONSTANT)

I can't find it in the Flash help... Thank you

Also I wonder if I can run some function on the import statement
or do I have to always call Util.init_my_static_vars() manually?

Regards
Alex

--
http://preferans.de

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com