Re: [Flashcoders] Q: Including class at compile w/o explicitly instantiating it

2007-08-13 Thread Alan MacDougall

Steven Sacks wrote:
If you do not do anything with an imported class, Flash will not 
compile it.


Or, to take it a step further, make a class named ClassRegistry (or some 
such), which defines but does not instantiate private static instances 
of every class you want to load dynamically. Then just define one 
instance of that registry in each class that will do dynamic instantiation.


class ColorRegistry
{
   // all extend Color
   private static var purple:Purple;
   private static var blue:Blue;
   private static var green:Green;
}

class ColorLoader
{
   private var registry:ColorRegistry;
  
   public function loadColor(className:String):Color

   {
  ClassLoader.getInstance(className);
   }
}

Every class which has an instance defined in ColorRegistry will be 
available for instantiation. It's a bit of a hassle when you're 
accustomed to stuff like Java's Class.forName(className) method, but it 
could be worse.


___
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


[Flashcoders] Q: Including class at compile w/o explicitly instantiating it

2007-08-10 Thread Rick Terrill
Hi everyone, it's my first time posting to the board.

I'm trying to figure something out, or if it's even possible.  I would like
to dynamically instantiate a class (via getDefinitionByName) but without
explicitly instantiating the object prior in the class.

An example (this is what I would like to be able to do):

package
{
import com.sweet.*;
import flash.utils.getDefinitionByName;

public class Foo
{
public function Foo()
{
 classRef = getDefinitionByName(com.sweet.SomeSweetClass) as
Class;
 var mySweetness:Object = new classRef();
}
 }
}

I figured that the import would take care of it, but it doesn't.  I have to
do at least one 'var ssc:SomeSweetClass = new SomeSweetClass();' and then it
will work.  If not, then I get a reference error like:
ReferenceError: Error #1065: Variable SomeSweetClass is not defined.

Is there any way to do this with Run-Time libraries, or some directive or
metadata or something?  Or is there something really obvious that I'm
missing?

t.i.a!

-- 
Rick Terrill
- www.rickterrill.com
- www.linkedin.com/in/rickterrill
___
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] Q: Including class at compile w/o explicitly instantiating it

2007-08-10 Thread Steve Mathews
Try just doing:
var ssc:SomeSweetClass;

On 8/10/07, Rick Terrill [EMAIL PROTECTED] wrote:
 Hi everyone, it's my first time posting to the board.

 I'm trying to figure something out, or if it's even possible.  I would like
 to dynamically instantiate a class (via getDefinitionByName) but without
 explicitly instantiating the object prior in the class.

 An example (this is what I would like to be able to do):

 package
 {
import com.sweet.*;
import flash.utils.getDefinitionByName;

public class Foo
{
public function Foo()
{
 classRef = getDefinitionByName(com.sweet.SomeSweetClass) as
 Class;
 var mySweetness:Object = new classRef();
}
 }
 }

 I figured that the import would take care of it, but it doesn't.  I have to
 do at least one 'var ssc:SomeSweetClass = new SomeSweetClass();' and then it
 will work.  If not, then I get a reference error like:
 ReferenceError: Error #1065: Variable SomeSweetClass is not defined.

 Is there any way to do this with Run-Time libraries, or some directive or
 metadata or something?  Or is there something really obvious that I'm
 missing?

 t.i.a!

 --
 Rick Terrill
 - www.rickterrill.com
 - www.linkedin.com/in/rickterrill
 ___
 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

___
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] Q: Including class at compile w/o explicitly instantiating it

2007-08-10 Thread Seth Caldwell
Hey Rick, no need to create an instance, but do create a variable of that
type, so the compiler knows to include that class in the package.

var ssc:SomeSweetClass;
===
Or simply cast to it in your call
classRef = getDefinitionByName(com.sweet.SomeSweetClass) as Class;
var mySweetness:SomeSweetClass = SomeSweetClass(new classRef());
==

Alternatively you can use compiler directives that tell flex builder to
package that class into the build, but that's annoying ;)


GL

Seth

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Steve
Mathews
Sent: Friday, August 10, 2007 2:37 PM
To: [EMAIL PROTECTED]; flashcoders@chattyfig.figleaf.com
Subject: Re: [Flashcoders] Q: Including class at compile w/o explicitly
instantiating it

Try just doing:
var ssc:SomeSweetClass;

On 8/10/07, Rick Terrill [EMAIL PROTECTED] wrote:
 Hi everyone, it's my first time posting to the board.

 I'm trying to figure something out, or if it's even possible.  I would
like
 to dynamically instantiate a class (via getDefinitionByName) but without
 explicitly instantiating the object prior in the class.

 An example (this is what I would like to be able to do):

 package
 {
import com.sweet.*;
import flash.utils.getDefinitionByName;

public class Foo
{
public function Foo()
{
 classRef = getDefinitionByName(com.sweet.SomeSweetClass) as
 Class;
 var mySweetness:Object = new classRef();
}
 }
 }

 I figured that the import would take care of it, but it doesn't.  I have
to
 do at least one 'var ssc:SomeSweetClass = new SomeSweetClass();' and then
it
 will work.  If not, then I get a reference error like:
 ReferenceError: Error #1065: Variable SomeSweetClass is not defined.

 Is there any way to do this with Run-Time libraries, or some directive or
 metadata or something?  Or is there something really obvious that I'm
 missing?

 t.i.a!

 --
 Rick Terrill
 - www.rickterrill.com
 - www.linkedin.com/in/rickterrill
 ___
 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

___
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


___
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] Q: Including class at compile w/o explicitly instantiating it

2007-08-10 Thread Steven Sacks

If you do not do anything with an imported class, Flash will not compile it.

One direct solution is to make a static boolean var in the class and 
access it once and it will force the class to compile.


var temp:Boolean = SomeClass.staticBoolean;
___
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