RE: [Flashcoders] Create an object by name

2007-03-21 Thread Danny Kodicek
   Might be interesting to know why you need to do this at all.
  
 
  I'm using an XML document to create a file. Without going into 
  details, each node of the XML is to be turned into an 
 object, based on the kind of node.
  So for example:
 
  xmlitem type='Big' size='3' /item type='Small' size='2'/xml
 
  This would become two objects, one an instance of 
 MyBigClass, one an 
  instance of MySmallClass. In an old version of this, each one was a 
  MovieClip with the appropriate linkage name. Now I'm trying 
 to do it 
  more flexibly with objects (so that in particular, each object type 
  can inherit a standard class, and so that I don't have to have a 
  separate movieClip for each object type).
 
  Danny
 

 Why would you not have 1 class with 2 properties type and size?
 What is different between the 2 items that requires different 
 classes? 
 The properties are the same. What does Big do that Small does not do?

Loads of things (remember, 'big' and 'small' are just examples here).
They're completely different objects. For example, one might refer to a bit
of text, another to a picture, etc. If I put it all into one class, I'd have
to fill it with Ifs and Switchs, which is what I'm trying to avoid.

(Btw, I was out of communication yesterday due to a break-in at our office,
so apologies to those people who sent replies that I didn't respond to)

Best
Danny

___
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] Create an object by name

2007-03-20 Thread Ron Wheeler




Might be interesting to know why you need to do this at all.



I'm using an XML document to create a file. Without going into details, each
node of the XML is to be turned into an object, based on the kind of node.
So for example:

xmlitem type='Big' size='3' /item type='Small' size='2'/xml

This would become two objects, one an instance of MyBigClass, one an
instance of MySmallClass. In an old version of this, each one was a
MovieClip with the appropriate linkage name. Now I'm trying to do it more
flexibly with objects (so that in particular, each object type can inherit a
standard class, and so that I don't have to have a separate movieClip for
each object type). 


Danny

  

Why would you not have 1 class with 2 properties type and size?
What is different between the 2 items that requires different classes? 
The properties are the same. What does Big do that Small does not do?


Ron
___
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] Create an object by name

2007-03-19 Thread Paul Andrews
- Original Message - 
From: Danny Kodicek [EMAIL PROTECTED]

To: flashcoders@chattyfig.figleaf.com
Sent: Monday, March 19, 2007 10:08 AM
Subject: [Flashcoders] Create an object by name



If I have a string, how can I make an object from the class it represents?
Eg:

I have class MyBigClass
the string className contains the text Big

I want to do something like
obj:Object = new(My + className + Class)()


Might be interesting to know why you need to do this at all.

Paul

snip


Danny

___
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] Create an object by name

2007-03-19 Thread Ian Thomas

Hello Danny,
 This short snippet should return you the constructor:

/** Returns the class constructor from a dotted path.
* e.g. [EMAIL PROTECTED] var
cons:Function=getConstructorFromPath(com.pkg.fred.Bucket); }
*/
public static function getConstructorFromPath(classPath:String):Function
{
var arr:Array=classPath.split(.);
var obj:Object=_global;
for(var i:Number=0;iarr.length;i++)
{
obj=obj[arr[i]];
}
return Function(obj);
}

Then just do var obj:Object=new cons();

Bear in mind that you must have referred to the class elsewhere in
your code, or it won't be compiled into the .swf. A simple import
won't do - you need to have a proper reference. Something as simple
as:
var imports:Array=[com.pkg.fred.Bucket,com.pkg.fred.Bucket2]; will do the job.

HTH,
  Ian

On 3/19/07, Danny Kodicek [EMAIL PROTECTED] wrote:

If I have a string, how can I make an object from the class it represents?
Eg:

I have class MyBigClass
the string className contains the text Big

I want to do something like
obj:Object = new(My + className + Class)()

And on the subject:
The docs say that when importing a package, only those classes that are
actually used are included with the swf, but in my case the classes that are
used are going to be dynamic and dependent on the data read by the movie at
runtime. Do I need to instantiate a dummy version of each class to ensure it
is included?

___
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] Create an object by name

2007-03-19 Thread Danny Kodicek
  Hello Danny,
   This short snippet should return you the constructor:
 
   /** Returns the class constructor from a dotted path.
   * e.g. [EMAIL PROTECTED] var
 cons:Function=getConstructorFromPath(com.pkg.fred.Bucket); }
   */
   public static function 
 getConstructorFromPath(classPath:String):Function
   {
   var arr:Array=classPath.split(.);
   var obj:Object=_global;
   for(var i:Number=0;iarr.length;i++)
   {
   obj=obj[arr[i]];
   }
   return Function(obj);
   }
 
 Then just do var obj:Object=new cons();

Thanks, Ian. So constructor functions are actually located in _global space?
That makes sense - is it always true, or do I need to ensure it in some way?
After all, if I do an import somewhere, that class is only available in the
scope of the import statement, not everywhere in the movie (I think?).

Again, sorry to be pushing these questions so much - I just find that once I
understand what's going on 'behind the scenes', I get much clearer about
what my side of things is. I'm still not entirely sure what import actually
*does* :)

Danny

___
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] Create an object by name

2007-03-19 Thread Danny Kodicek
  If I have a string, how can I make an object from the class 
 it represents?
  Eg:
 
  I have class MyBigClass
  the string className contains the text Big
 
  I want to do something like
  obj:Object = new(My + className + Class)()
 

Paul:

 Might be interesting to know why you need to do this at all.

I'm using an XML document to create a file. Without going into details, each
node of the XML is to be turned into an object, based on the kind of node.
So for example:

xmlitem type='Big' size='3' /item type='Small' size='2'/xml

This would become two objects, one an instance of MyBigClass, one an
instance of MySmallClass. In an old version of this, each one was a
MovieClip with the appropriate linkage name. Now I'm trying to do it more
flexibly with objects (so that in particular, each object type can inherit a
standard class, and so that I don't have to have a separate movieClip for
each object type). 

Danny

___
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] Create an object by name

2007-03-19 Thread Ian Thomas

Hi Danny,
 An import statement is just a compiler-friendly shortcut. It has no
effect whatsoever on the final code.

Saying:

import com.pkg.fred.Bucket;

// later
var bucket:Bucket=new Bucket();

is identical to saying just:
var bucket:com.pkg.fred.Bucket=new com.pkg.fred.Bucket();

That's all it is. A convent bit of syntactic sugar. It's exactly the
same in Java.

Simply using the import line by itself will have no effect on the
compilation (try importing 300 classes and compiling your app - the
filesize will not increase. :-) )

As soon as you refer to the class in some way that ensures it is
compiled in (i.e. an import will not do, but any concrete reference
such as the line above will do) then that class is available to any
other piece of code within that same Flash VM, with the following
exception: IIRC SWFs compiled for Flash 6 and Flash 7 don't share
thair global namespace (so I'd imagine that you'd have issues there).
Obviously the globals/classes won't be shared between AVM1 and AVM2
(but then, AS3 has a totally different class locating/loading
mechanism anyway).

For AS2, yes, class constructors are always located in the _global
space as soon as that class is loaded. (In fact, you can load a
_different version_ of a class at runtime if you delete the existing
class from the global space).

I hope that clears it up. Of course, I could just be babbling. :-)

Cheers,
  Ian

P.S. How're the interactive storytelling things going..?

On 3/19/07, Danny Kodicek [EMAIL PROTECTED] wrote:

  Hello Danny,


Thanks, Ian. So constructor functions are actually located in _global space?
That makes sense - is it always true, or do I need to ensure it in some way?
After all, if I do an import somewhere, that class is only available in the
scope of the import statement, not everywhere in the movie (I think?).

Again, sorry to be pushing these questions so much - I just find that once I
understand what's going on 'behind the scenes', I get much clearer about
what my side of things is. I'm still not entirely sure what import actually
*does* :)

Danny


___
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] Create an object by name

2007-03-19 Thread Paul Andrews
- Original Message - 
From: Danny Kodicek [EMAIL PROTECTED]

To: flashcoders@chattyfig.figleaf.com


I'm still not entirely sure what import actually
*does* :)


It tells flash where the class definitions can be found and distinguishes 
between classes of the same name, but different packages.


You seem to be in a mega hurry Danny!

Paul


Danny

___
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] Create an object by name

2007-03-19 Thread Karina Steffens
Hi Danny,

The idea of the import statement is to specify which class namespaces you
want to use. For example, there could be multiple packages that contain a
class named Danny:
 com.kodicek.Danny
 com.day.lewis.Danny

If you wanted to use the first class, you'd need to write all of it every
time you wanted to instantiate it, like this:

myClass = new com.kodicek.Danny ()
myClone = new com.kodicek.Danny ()

But to make it easier, you can import it at the top of the containing class:

 import com.kodicek.Danny;

Having imported it, you let the containing class know which Danny you want
to be using, so then you can instantiate it without appending the full
package name each time:

myClass = new Danny()
myClone = new Danny()

You can also use:
  import com.kodicek.*;

And that would import all the classes in the specified package, saving you
the hassle of importing them one by one - but Flash will only compile the
class or classes you end up using in the script, keeping the swf size just
as small as if you'd used import com.kodicek.Danny.

I hope that wasn't over-explaining: I know you're not exactly a newbie to
programming ;)

Karina



 -Original Message-
 From: Danny Kodicek [mailto:[EMAIL PROTECTED] 
 Sent: 19 March 2007 11:45
 To: flashcoders@chattyfig.figleaf.com
 Subject: RE: [Flashcoders] Create an object by name
 
   Hello Danny,
This short snippet should return you the constructor:
  
  /** Returns the class constructor from a dotted path.
  * e.g. [EMAIL PROTECTED] var
  cons:Function=getConstructorFromPath(com.pkg.fred.Bucket); }
  */
  public static function
  getConstructorFromPath(classPath:String):Function
  {
  var arr:Array=classPath.split(.);
  var obj:Object=_global;
  for(var i:Number=0;iarr.length;i++)
  {
  obj=obj[arr[i]];
  }
  return Function(obj);
  }
  
  Then just do var obj:Object=new cons();
 
 Thanks, Ian. So constructor functions are actually located in 
 _global space?
 That makes sense - is it always true, or do I need to ensure 
 it in some way?
 After all, if I do an import somewhere, that class is only 
 available in the scope of the import statement, not 
 everywhere in the movie (I think?).
 
 Again, sorry to be pushing these questions so much - I just 
 find that once I understand what's going on 'behind the 
 scenes', I get much clearer about what my side of things is. 
 I'm still not entirely sure what import actually
 *does* :)
 
 Danny
 
 ___
 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] Create an object by name

2007-03-19 Thread Hans Wichman

Hi,
new eval(_global.mypackage.MyClass) does the trick as well I believe.

greetz
JC


On 3/19/07, Danny Kodicek [EMAIL PROTECTED] wrote:


  If I have a string, how can I make an object from the class
 it represents?
  Eg:
 
  I have class MyBigClass
  the string className contains the text Big
 
  I want to do something like
  obj:Object = new(My + className + Class)()


Paul:

 Might be interesting to know why you need to do this at all.

I'm using an XML document to create a file. Without going into details,
each
node of the XML is to be turned into an object, based on the kind of node.
So for example:

xmlitem type='Big' size='3' /item type='Small' size='2'/xml

This would become two objects, one an instance of MyBigClass, one an
instance of MySmallClass. In an old version of this, each one was a
MovieClip with the appropriate linkage name. Now I'm trying to do it more
flexibly with objects (so that in particular, each object type can inherit
a
standard class, and so that I don't have to have a separate movieClip for
each object type).

Danny

___
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] Create an object by name

2007-03-19 Thread Ian Thomas

On 3/19/07, Ian Thomas [EMAIL PROTECTED] wrote:


That's all it is. A convent bit of syntactic sugar. It's exactly the
same in Java.


Um... _convenient_, obviously. Although that does conjure up some
wacky images...

Ian
___
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] Create an object by name

2007-03-19 Thread Danny Kodicek
  Hi Danny,
   An import statement is just a compiler-friendly shortcut. 
 It has no effect whatsoever on the final code.
 
 Saying:
 
 import com.pkg.fred.Bucket;
 
 // later
 var bucket:Bucket=new Bucket();
 
 is identical to saying just:
 var bucket:com.pkg.fred.Bucket=new com.pkg.fred.Bucket();
 
 That's all it is. A convent bit of syntactic sugar. It's 
 exactly the same in Java.

You know something? I actually knew that somewhere in my head, but it had
been temporarily squished. Thanks.

 As soon as you refer to the class in some way that ensures it 
 is compiled in (i.e. an import will not do, but any concrete 
 reference such as the line above will do) then that class is 
 available to any other piece of code within that same Flash 
 VM, with the following
 exception: IIRC SWFs compiled for Flash 6 and Flash 7 don't 
 share thair global namespace (so I'd imagine that you'd have 
 issues there).

Brilliant, that makes a *lot* more sense. In particular, it means I don't
have to import all my packages into every blimmin' class.

 P.S. How're the interactive storytelling things going..?

:) 

Try me again in about a year and a half. We've been head down in a lot of
tech-heavy and content-light development recently, but who knows, once this
current stuff is done we might go back to something a bit more creative...

Danny

___
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] Create an object by name

2007-03-19 Thread Danny Kodicek
   I'm still not entirely sure what import actually
  *does* :)
 
 It tells flash where the class definitions can be found and 
 distinguishes between classes of the same name, but different 
 packages.
 
 You seem to be in a mega hurry Danny!

I've been working on my current task for about nine months and I'm
approaching the home stretch. I want the damn thing finished. (I was also
hoping to have this bit done before I go on holiday next week!)

Plus I never get any work done unless I'm in a hurry...

Danny

___
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] Create an object by name

2007-03-19 Thread Danny Kodicek
 
  I'm still not entirely sure what import actually
  *does* :)
 
 It tells flash where the class definitions can be found and 
 distinguishes between classes of the same name, but different 
 packages.

You know, it occurs to me that import is an astonishingly bad name for this
statement. Poorly named methods and properties can really screw up
understanding, and not just in third party code. Sometimes I think properly
named variables or methods can do half your coding for you. Why is it not
called something else? I can think of three better names immediately:
pointTo, locate or classAt

Danny

___
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] Create an object by name

2007-03-19 Thread Paul Andrews
- Original Message - 
From: Danny Kodicek [EMAIL PROTECTED]
To: flashcoders@chattyfig.figleaf.com
Sent: Monday, March 19, 2007 2:36 PM
Subject: RE: [Flashcoders] Create an object by name



   I'm still not entirely sure what import actually
   *does* :)
 
  It tells flash where the class definitions can be found and
  distinguishes between classes of the same name, but different
  packages.

 You know, it occurs to me that import is an astonishingly bad name for
this
 statement. Poorly named methods and properties can really screw up
 understanding, and not just in third party code. Sometimes I think
properly
 named variables or methods can do half your coding for you. Why is it not
 called something else? I can think of three better names immediately:
 pointTo, locate or classAt

Sounds like three worse names, I'm afraid. Import is really the industry
standard here (in other languages besides Actionscript)
and it would be bad to move from it.

IMHO it's pretty descriptive - you import these classes into your project.

On reflection, my description is a bit superficial. Import is dealing with
class namespaces and packages (collections of classes).

I'd better stop now.

Paul


 Danny

 ___
 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] Create an object by name

2007-03-19 Thread Steven Sacks | BLITZ
Most of the time, what I've seen is setting a temporary var to either an
instance of the class, or in the case of a static class, setting it to a
reference to the class.

var myClass:MyClass = new com.client.project.package.MyClass();
or
var myClass:MyClass = com.client.project.package.MyClass;

I have to wonder, though, if there's not a better way to accomplish what
you're trying to achieve.
___
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