Re: [Flashcoders] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-08 Thread Bernard Poulin

Alternative way of instanciating a class without a library and without the
__Package hack either.

Create a class with this function:
function attachClassMovie(parentmc:MovieClip, className:Function,
instanceName:String, depth:Number, argv:Array):MovieClip
{
// Create emptyMovieClip
var new_mc:MovieClip = parentmc.createEmptyMovieClip(instanceName, depth);

// Save classe prototype
new_mc.__proto__ = className.prototype;

// apply the constructor
className.apply(new_mc, argv);

// return new clip
return new_mc;
}

var mc = attachClassMovie(parent_mc, com.Class, child, 10, [param1,
param2]);


2006/7/7, Julian Bleecker [EMAIL PROTECTED]:


Ian,

Those casting gymnastics definitely help — thanks a lot.

Julian

On Jul 7, 2006, at 9:27 PDT, Ian Thomas wrote:

 On 7/7/06, Julian Bleecker [EMAIL PROTECTED] wrote:
 One other thing occurred to me on this topic, that might actually
 save the trouble of using a hash table, which AS direly needs.

 Is there a way to summon forth a class that's been instantiated in
 any of the ways described below, by name?

 In other words, if I've done this:

 for(var i:Number = 0; i  12; i++) {
   Object.registerClass(symbolName,FooA);
   var clip:FooA=FooA(myMovie.attachMovie
 (symbolName,anInstanceName_+i,depth));
 }

 And elsewhere, I want to summon forth these dynamically in another
 loop or otherwise (something I might normally do by stuffing the
 instances in a hash or map somewhere and using the name as the key) -
 can I do that in some fashion? Is there an AS idiom for obtaining a
 reference to a MovieClip (or other runtime object) by name?

 Julian

 Firstly, Actionscript does have the equivalent of a HashMap.
 Everything derived from Object can be treated like so:

 var obj:Object=new Object();
 obj[someKey]=Hello;
 trace(obj[someKey]); // traces Hello

 The bracket access on an object actually accesses the properties and
 methods of that object.
 Hence:
 var myClip:MovieClip = ...some movieclip...
 trace(myClip._visible);
 trace(myClip[_visible]); // equivalent to the last line
 myClip.doSomething(1,2,3);
 myClip[doSomething](1,2,3); // equivalent to last line.
 myClip._y=20;
 myClip[_y]=20; // again, equivalent

 When you create/attach an instance of a MovieClip to a parent
 movieclip, you are actually creating new properties on that parent
 clip.

 So:
 var myClip:MovieClip=someClip.attachMovie(Symbol,aNewClip,1);
 trace(myClip==this[aNewClip); // traces 'true'

 To get back to your original question, this means you can type:
 var myClip:MovieClip=myMovie[anInstanceName_0];

 to retrieve your clip.

 HTH,
  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

___
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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-07 Thread Ian Thomas

Hi Julian,
 They do return references.

 You just have to cast them to the correct type.

 e.g. var clip:MyClip=MyClip(attachMovie(SymbolName,instanceName,depth));

HTH,
 Ian

On 7/7/06, Julian Bleecker [EMAIL PROTECTED] wrote:

Yeah, I think it gets worse. I'm used to a pattern where you create a
whole bunch of something — so, back to the problem I originally
asked, if I want have my mainClip create a dozen subClip instances
and tuck each one of those instances in an Array for later use,
especially calling that useful method. I guess I'm asking how one can
call a method on an instance where the instance's name is derived at
runtime.

For instance, in this example you provided, which works for the
single subClip00 instance variable, how would I do the same thing,
only with a runtime derived name?

class mainClip extends MovieClip
{
public var subClip00:subClip;

function mainClip() {
trace(new mainClip!);

init();
}

function init():Void {
for(int i=0; i12; i++) {
attachMovie(subClip, subClip_+i, 
this.getNextHighestDepth());
//this.subClip00.usefulMethod(); this won't work..how 
to call a
method with no reference — only a name?
}
}
}

But, the bigger question is: why don't things like attachMovie or
such return references to the things they're attaching?

Julian

On Jul 6, 2006, at 20:50 PDT, Mike Britton wrote:

 Perhaps, but you never know: someone on this list may have a better
 solution for your problem.

 Mike
 ___
 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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-07 Thread Julian Bleecker
Ah, slowly getting it..I've dug in so deeply with Java idioms that  
it's almost like being Charleton Heston in Planet of the Apes..


.julian.

Julian Bleecker, Ph.D.
http://research.techkwondo.com
[EMAIL PROTECTED]



On Jul 6, 2006, at 23:28 PDT, Ian Thomas wrote:


Hi Julian,
 They do return references.

 You just have to cast them to the correct type.

 e.g. var clip:MyClip=MyClip(attachMovie 
(SymbolName,instanceName,depth));


HTH,
 Ian

On 7/7/06, Julian Bleecker [EMAIL PROTECTED] wrote:

Yeah, I think it gets worse. I'm used to a pattern where you create a
whole bunch of something — so, back to the problem I originally
asked, if I want have my mainClip create a dozen subClip instances
and tuck each one of those instances in an Array for later use,
especially calling that useful method. I guess I'm asking how one can
call a method on an instance where the instance's name is derived at
runtime.

For instance, in this example you provided, which works for the
single subClip00 instance variable, how would I do the same thing,
only with a runtime derived name?

class mainClip extends MovieClip
{
public var subClip00:subClip;

function mainClip() {
trace(new mainClip!);

init();
}

function init():Void {
for(int i=0; i12; i++) {
attachMovie(subClip, subClip_+i,  
this.getNextHighestDepth());
//this.subClip00.usefulMethod(); this  
won't work..how to call a

method with no reference — only a name?
}
}
}

But, the bigger question is: why don't things like attachMovie or
such return references to the things they're attaching?

Julian

On Jul 6, 2006, at 20:50 PDT, Mike Britton wrote:

 Perhaps, but you never know: someone on this list may have a better
 solution for your problem.

 Mike
 ___
 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


___
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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-07 Thread Ian Thomas

Hi Julian,
 Now I've had my first cup of coffee I'll try to explain it more clearly. :-)

 In most cases AS2 works very similarly to Java in terms of
inheritance, instantiation and casting and the like - the only main
gotcha is that the class casting operator is MyClass(x) rather than
(MyClass)x - which looks suspiciously like a constructor and can
confuse the issue.

 The major difference is when we come to MovieClips, or
MovieClip-a-likes (TextField, for example). For historical reasons an
object which is of class MovieClip or an object which derives from
class MovieClip can't be instantiated directly via new - so new
MovieClip() or new FooA() (which extends MovieClip) will not work.
(Roll on AS3!)

 You can create a new, plain, vanilla MovieClip like so:

var clip:MovieClip=myMovie.createEmptyMovieClip(instanceName,depth);

 You can create a MovieClip which represents a symbol in the library like so:
var clip:MovieClip=myMovie.attachMovie(symbolName,instanceName,depth);

Both of these operations dynamically create a new property,
'instanceName', on myMovie. If myMovie were a plain MovieClip (and
thus dynamically typed), you could type:

myMovie.createEmptyMovieClip(fred,depth);
myMovie.fred._visible=false; // do something to the clip
var clip:MovieClip=myMovie.fred; // grab a reference to the clip

(As an aside, if you're working with a non-dynamic class as the parent
movie clip i.e. something derived from MovieClip, the compiler
complains because it doesn't know about the variable fred - you can
type:
var clip:MovieClip=myMovie[fred];
to get around this.)

To create an object associated with a symbol that is of a type derived
from MovieClip (e.g. FooA extends MovieClip) you can either:

 Set the class name in the linkage dialog of the library symbol.
 var clip:FooA=FooA(myMovie.attachMovie(symbolName,instanceName,depth));
 (or
 var clip:MovieClip=myMovie.attachMovie(symbolName,instanceName,depth);
 var foo:FooA=FooA(clip);
 It's the same thing)

or purely by code:

 Object.registerClass(symbolName,FooA);
 var clip:FooA=FooA(myMovie.attachMovie(symbolName,instanceName,depth));

If you want to create an object which is derived from MovieClip that
is _not_ associated with a symbol instance (i.e. effectively an
emptyMovieClip with an associated class), you can do this arcane hack:

(For arguments sake, let's say FooA is actually com.misc.FooA which
extends MovieClip)
var symbolName:String=__Packages.com.misc.FooA;
Object.registerClass(symbolName,FooA);
var clip:FooA=FooA(myMovie.attachMovie(symbolName,instanceName,depth));

(The trick here is that for each class, Flash registers an 'invisible'
symbol with the name __Packages.full class and package)

I think that covers almost all you need to know about instantiating
MovieClips. :-)

I came from a Java background too (amongst other things), and it does
all sort of make logical sense, if you think of createEmptyMovieClip
and attachMovie as being object factories. But like I say, roll on
AS3, which gets rid of a lot of these historical peculiarities.

Hope that's more help,
 Ian


On 7/7/06, Julian Bleecker [EMAIL PROTECTED] wrote:

Ah, slowly getting it..I've dug in so deeply with Java idioms that
it's almost like being Charleton Heston in Planet of the Apes..

.julian.

Julian Bleecker, Ph.D.
http://research.techkwondo.com
[EMAIL PROTECTED]



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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-07 Thread Julian Bleecker
That's great Ian — thanks for the help! Each of those little idioms  
makes sense when described — I never would've figured these out just  
whacking at various permutations, particularly the very baroque  
incantation leveraging the invisible symbol names.


I guess I should be looking forward to AS3, too — presumably it is  
more strongly typed and gets rid of the dusty historical legacies.


Julian

On Jul 7, 2006, at 0:25 PDT, Ian Thomas wrote:


Hi Julian,
 Now I've had my first cup of coffee I'll try to explain it more  
clearly. :-)


 In most cases AS2 works very similarly to Java in terms of
inheritance, instantiation and casting and the like - the only main
gotcha is that the class casting operator is MyClass(x) rather than
(MyClass)x - which looks suspiciously like a constructor and can
confuse the issue.

 The major difference is when we come to MovieClips, or
MovieClip-a-likes (TextField, for example). For historical reasons an
object which is of class MovieClip or an object which derives from
class MovieClip can't be instantiated directly via new - so new
MovieClip() or new FooA() (which extends MovieClip) will not work.
(Roll on AS3!)

 You can create a new, plain, vanilla MovieClip like so:

var clip:MovieClip=myMovie.createEmptyMovieClip(instanceName,depth);

 You can create a MovieClip which represents a symbol in the  
library like so:

var clip:MovieClip=myMovie.attachMovie(symbolName,instanceName,depth);

Both of these operations dynamically create a new property,
'instanceName', on myMovie. If myMovie were a plain MovieClip (and
thus dynamically typed), you could type:

myMovie.createEmptyMovieClip(fred,depth);
myMovie.fred._visible=false; // do something to the clip
var clip:MovieClip=myMovie.fred; // grab a reference to the clip

(As an aside, if you're working with a non-dynamic class as the parent
movie clip i.e. something derived from MovieClip, the compiler
complains because it doesn't know about the variable fred - you can
type:
var clip:MovieClip=myMovie[fred];
to get around this.)

To create an object associated with a symbol that is of a type derived
from MovieClip (e.g. FooA extends MovieClip) you can either:

 Set the class name in the linkage dialog of the library symbol.
 var clip:FooA=FooA(myMovie.attachMovie 
(symbolName,instanceName,depth));

 (or
 var clip:MovieClip=myMovie.attachMovie 
(symbolName,instanceName,depth);

 var foo:FooA=FooA(clip);
 It's the same thing)

or purely by code:

 Object.registerClass(symbolName,FooA);
 var clip:FooA=FooA(myMovie.attachMovie 
(symbolName,instanceName,depth));


If you want to create an object which is derived from MovieClip that
is _not_ associated with a symbol instance (i.e. effectively an
emptyMovieClip with an associated class), you can do this arcane hack:

(For arguments sake, let's say FooA is actually com.misc.FooA which
extends MovieClip)
var symbolName:String=__Packages.com.misc.FooA;
Object.registerClass(symbolName,FooA);
var clip:FooA=FooA(myMovie.attachMovie 
(symbolName,instanceName,depth));


(The trick here is that for each class, Flash registers an 'invisible'
symbol with the name __Packages.full class and package)

I think that covers almost all you need to know about instantiating
MovieClips. :-)

I came from a Java background too (amongst other things), and it does
all sort of make logical sense, if you think of createEmptyMovieClip
and attachMovie as being object factories. But like I say, roll on
AS3, which gets rid of a lot of these historical peculiarities.

Hope that's more help,
 Ian


On 7/7/06, Julian Bleecker [EMAIL PROTECTED] wrote:

Ah, slowly getting it..I've dug in so deeply with Java idioms that
it's almost like being Charleton Heston in Planet of the Apes..

.julian.

Julian Bleecker, Ph.D.
http://research.techkwondo.com
[EMAIL PROTECTED]



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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-07 Thread Alan MacDougall

Julian Bleecker wrote:

That's great Ian — thanks for the help! Each of those little idioms  
makes sense when described — I never would've figured these out just  
whacking at various permutations, particularly the very baroque  
incantation leveraging the invisible symbol names.


You may find it more convenient to consider MovieClip items as 
primitives -- or at least not worth your time to extend -- and create 
classes which wrap them. If you just want MovieClips to do particular 
things, or exhibit polymorphic behavior, you can probably get away with 
this:


class Foo
{
   private var myClip:MovieClip;

   public function Foo()
   {
  // create the MovieClip, possibly by
  // creating a new instance from the library
   }

   public function doThing()
   {
  myClip.doSomething();
  myClip.doSomethingElse();
  var tween:Tween = new Tween(some properties, myClip);
  trace(And so on);
   }
}

I find this approach easier to work with and, since you could have more 
than one MovieClip in your custom object, more flexible. (Sure, Flash 
also lets you nest MovieClips ad infinitum, but moving away from 
parent.child.child.child is another benefit of going Java style.)


___
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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-07 Thread Julian Bleecker
One other thing occurred to me on this topic, that might actually  
save the trouble of using a hash table, which AS direly needs.


Is there a way to summon forth a class that's been instantiated in  
any of the ways described below, by name?


In other words, if I've done this:

for(var i:Number = 0; i  12; i++) {
 Object.registerClass(symbolName,FooA);
 var clip:FooA=FooA(myMovie.attachMovie 
(symbolName,anInstanceName_+i,depth));

}

And elsewhere, I want to summon forth these dynamically in another  
loop or otherwise (something I might normally do by stuffing the  
instances in a hash or map somewhere and using the name as the key) -  
can I do that in some fashion? Is there an AS idiom for obtaining a  
reference to a MovieClip (or other runtime object) by name?


Julian

On Jul 7, 2006, at 0:25 PDT, Ian Thomas wrote:


Hi Julian,
 Now I've had my first cup of coffee I'll try to explain it more  
clearly. :-)


 In most cases AS2 works very similarly to Java in terms of
inheritance, instantiation and casting and the like - the only main
gotcha is that the class casting operator is MyClass(x) rather than
(MyClass)x - which looks suspiciously like a constructor and can
confuse the issue.

 The major difference is when we come to MovieClips, or
MovieClip-a-likes (TextField, for example). For historical reasons an
object which is of class MovieClip or an object which derives from
class MovieClip can't be instantiated directly via new - so new
MovieClip() or new FooA() (which extends MovieClip) will not work.
(Roll on AS3!)

 You can create a new, plain, vanilla MovieClip like so:

var clip:MovieClip=myMovie.createEmptyMovieClip(instanceName,depth);

 You can create a MovieClip which represents a symbol in the  
library like so:

var clip:MovieClip=myMovie.attachMovie(symbolName,instanceName,depth);

Both of these operations dynamically create a new property,
'instanceName', on myMovie. If myMovie were a plain MovieClip (and
thus dynamically typed), you could type:

myMovie.createEmptyMovieClip(fred,depth);
myMovie.fred._visible=false; // do something to the clip
var clip:MovieClip=myMovie.fred; // grab a reference to the clip

(As an aside, if you're working with a non-dynamic class as the parent
movie clip i.e. something derived from MovieClip, the compiler
complains because it doesn't know about the variable fred - you can
type:
var clip:MovieClip=myMovie[fred];
to get around this.)

To create an object associated with a symbol that is of a type derived
from MovieClip (e.g. FooA extends MovieClip) you can either:

 Set the class name in the linkage dialog of the library symbol.
 var clip:FooA=FooA(myMovie.attachMovie 
(symbolName,instanceName,depth));

 (or
 var clip:MovieClip=myMovie.attachMovie 
(symbolName,instanceName,depth);

 var foo:FooA=FooA(clip);
 It's the same thing)

or purely by code:

 Object.registerClass(symbolName,FooA);
 var clip:FooA=FooA(myMovie.attachMovie 
(symbolName,instanceName,depth));


If you want to create an object which is derived from MovieClip that
is _not_ associated with a symbol instance (i.e. effectively an
emptyMovieClip with an associated class), you can do this arcane hack:

(For arguments sake, let's say FooA is actually com.misc.FooA which
extends MovieClip)
var symbolName:String=__Packages.com.misc.FooA;
Object.registerClass(symbolName,FooA);
var clip:FooA=FooA(myMovie.attachMovie 
(symbolName,instanceName,depth));


(The trick here is that for each class, Flash registers an 'invisible'
symbol with the name __Packages.full class and package)

I think that covers almost all you need to know about instantiating
MovieClips. :-)

I came from a Java background too (amongst other things), and it does
all sort of make logical sense, if you think of createEmptyMovieClip
and attachMovie as being object factories. But like I say, roll on
AS3, which gets rid of a lot of these historical peculiarities.

Hope that's more help,
 Ian


On 7/7/06, Julian Bleecker [EMAIL PROTECTED] wrote:

Ah, slowly getting it..I've dug in so deeply with Java idioms that
it's almost like being Charleton Heston in Planet of the Apes..

.julian.

Julian Bleecker, Ph.D.
http://research.techkwondo.com
[EMAIL PROTECTED]



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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-07 Thread Ian Thomas

On 7/7/06, Julian Bleecker [EMAIL PROTECTED] wrote:

One other thing occurred to me on this topic, that might actually
save the trouble of using a hash table, which AS direly needs.

Is there a way to summon forth a class that's been instantiated in
any of the ways described below, by name?

In other words, if I've done this:

for(var i:Number = 0; i  12; i++) {
  Object.registerClass(symbolName,FooA);
  var clip:FooA=FooA(myMovie.attachMovie
(symbolName,anInstanceName_+i,depth));
}

And elsewhere, I want to summon forth these dynamically in another
loop or otherwise (something I might normally do by stuffing the
instances in a hash or map somewhere and using the name as the key) -
can I do that in some fashion? Is there an AS idiom for obtaining a
reference to a MovieClip (or other runtime object) by name?

Julian


Firstly, Actionscript does have the equivalent of a HashMap.
Everything derived from Object can be treated like so:

var obj:Object=new Object();
obj[someKey]=Hello;
trace(obj[someKey]); // traces Hello

The bracket access on an object actually accesses the properties and
methods of that object.
Hence:
var myClip:MovieClip = ...some movieclip...
trace(myClip._visible);
trace(myClip[_visible]); // equivalent to the last line
myClip.doSomething(1,2,3);
myClip[doSomething](1,2,3); // equivalent to last line.
myClip._y=20;
myClip[_y]=20; // again, equivalent

When you create/attach an instance of a MovieClip to a parent
movieclip, you are actually creating new properties on that parent
clip.

So:
var myClip:MovieClip=someClip.attachMovie(Symbol,aNewClip,1);
trace(myClip==this[aNewClip); // traces 'true'

To get back to your original question, this means you can type:
var myClip:MovieClip=myMovie[anInstanceName_0];

to retrieve your clip.

HTH,
 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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-07 Thread Ian Thomas

(To be clear - Object isn't quite the equivalent of HashMap, as you
can't natively specify hash codes etc. etc. But for many purposes, it
serves the same uses.)

Ian

On 7/7/06, Ian Thomas [EMAIL PROTECTED] wrote:



Firstly, Actionscript does have the equivalent of a HashMap.
Everything derived from Object can be treated like so:

___
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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-07 Thread Julian Bleecker

Alan,

Thanks - that gives me a different approach to try out that sounds  
very promising.


Julian

On Jul 7, 2006, at 8:59 PDT, Alan MacDougall wrote:


Julian Bleecker wrote:

That's great Ian — thanks for the help! Each of those little  
idioms  makes sense when described — I never would've figured  
these out just  whacking at various permutations, particularly the  
very baroque  incantation leveraging the invisible symbol names.


You may find it more convenient to consider MovieClip items as  
primitives -- or at least not worth your time to extend -- and  
create classes which wrap them. If you just want MovieClips to do  
particular things, or exhibit polymorphic behavior, you can  
probably get away with this:


class Foo
{
   private var myClip:MovieClip;

   public function Foo()
   {
  // create the MovieClip, possibly by
  // creating a new instance from the library
   }

   public function doThing()
   {
  myClip.doSomething();
  myClip.doSomethingElse();
  var tween:Tween = new Tween(some properties, myClip);
  trace(And so on);
   }
}

I find this approach easier to work with and, since you could have  
more than one MovieClip in your custom object, more flexible.  
(Sure, Flash also lets you nest MovieClips ad infinitum, but moving  
away from parent.child.child.child is another benefit of going Java  
style.)


___
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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-07 Thread Julian Bleecker

Ian,

Those casting gymnastics definitely help — thanks a lot.

Julian

On Jul 7, 2006, at 9:27 PDT, Ian Thomas wrote:


On 7/7/06, Julian Bleecker [EMAIL PROTECTED] wrote:

One other thing occurred to me on this topic, that might actually
save the trouble of using a hash table, which AS direly needs.

Is there a way to summon forth a class that's been instantiated in
any of the ways described below, by name?

In other words, if I've done this:

for(var i:Number = 0; i  12; i++) {
  Object.registerClass(symbolName,FooA);
  var clip:FooA=FooA(myMovie.attachMovie
(symbolName,anInstanceName_+i,depth));
}

And elsewhere, I want to summon forth these dynamically in another
loop or otherwise (something I might normally do by stuffing the
instances in a hash or map somewhere and using the name as the key) -
can I do that in some fashion? Is there an AS idiom for obtaining a
reference to a MovieClip (or other runtime object) by name?

Julian


Firstly, Actionscript does have the equivalent of a HashMap.
Everything derived from Object can be treated like so:

var obj:Object=new Object();
obj[someKey]=Hello;
trace(obj[someKey]); // traces Hello

The bracket access on an object actually accesses the properties and
methods of that object.
Hence:
var myClip:MovieClip = ...some movieclip...
trace(myClip._visible);
trace(myClip[_visible]); // equivalent to the last line
myClip.doSomething(1,2,3);
myClip[doSomething](1,2,3); // equivalent to last line.
myClip._y=20;
myClip[_y]=20; // again, equivalent

When you create/attach an instance of a MovieClip to a parent
movieclip, you are actually creating new properties on that parent
clip.

So:
var myClip:MovieClip=someClip.attachMovie(Symbol,aNewClip,1);
trace(myClip==this[aNewClip); // traces 'true'

To get back to your original question, this means you can type:
var myClip:MovieClip=myMovie[anInstanceName_0];

to retrieve your clip.

HTH,
 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


___
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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-06 Thread Julian Bleecker

Okay, here's the drill.

I have a MovieClip — call it FooA — that's been linked to an AS2  
class — call it FooA_Class — (that extends MovieClip and does lots of  
other useful things.)


In that MovieClip, I have another MovieClip — SubFooA — that's been  
exported and given a proper instance name. In FooA_Class there's an  
instance variable that has the same name as the instance name for  
SubFooA (that idiom is weird, but okay..)


I would like to, in ActionScript, dynamically instantiate and render  
onto the stage several instances of FooA — it's a MovieClip, after  
all — it has some visual things in itself, like colored blocks and  
stuff.


Now, I want to also, in ActionScript, call a bunch of the useful  
methods that FooA_Class has.


What's the idiom for doing such a thing??

I've tried what the Java guy in me says to, like instantiate FooA and  
do things with it:


var mFooA:FooA = new FooA();
mFooA.doSomeMethod();

But, now I can't get it on the stage properly, even with various  
incarnations of attachMovie in either the constructor of FooA, or  
right there after the constructor (registerClass/attachMovie)


Then I try this confusing idiom:

Object.registerClass(mFooA, FooA);
_root.attachMovie(FooA, FooA, 1);

The MovieClip FooA appears on the stage, but that's it — I can't call  
useful methods on it as I have no proper handle to the instance.


If I do this:

Object.registerClass(mFooA, FooA);
var aObject:Object = _root.attachMovie(FooA, FooA, 1);

what is returned from attachMovie isn't properly cast to my class  
type — which is a bit odd. I mean, if I do this:


Object.registerClass(mFooA, FooA);
var aObject:FooA_Class = _root.attachMovie(FooA, FooA, 1);

Flash complains — whatever the equivalent of a class cast error it  
spouts..type mismatch or something?


So, the basic question is this: how can I programmatically  
instantiate and deliver to the stage a movie clip linked to my own  
custom class (which extends MovieClip) and then actually call the  
useful methods contained within that linked custom class?


This _has_ to be easy, no?

Julian


Julian Bleecker, Ph.D.
http://research.techkwondo.com
[EMAIL PROTECTED]



___
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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-06 Thread Mike Britton

Hey Julian,

I feel your pain.  Take a look at this example:
http://www.randomusa.com/flash/downloads/tojulian.zip

Mike Britton
___
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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-06 Thread Julian Bleecker

Cripes.

Thanks Mike! So, this magic of turning a named instance into the name  
of the instance variable gets carried to its logical, but somewhat  
weird, conclusion.


Julian

On Jul 6, 2006, at 19:30 PDT, Mike Britton wrote:


Hey Julian,

I feel your pain.  Take a look at this example:
http://www.randomusa.com/flash/downloads/tojulian.zip

Mike Britton
___
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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-06 Thread Mike Britton

Perhaps, but you never know: someone on this list may have a better
solution for your problem.

Mike
___
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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-06 Thread Ian Thomas

Hi Julian,
 You were nearly there with:
Object.registerClass(mFooA, FooA);
var aObject:FooA_Class = _root.attachMovie(FooA, FooA, 1);

Just change it to:
Object.registerClass(mFooA, FooA);
var aObject:FooA_Class = FooA_Class(_root.attachMovie(FooA, FooA, 1));

(as Class(x) is the equivalent of the Java class cast operator (Class)x)

HTH,
 Ian

On 7/7/06, Mike Britton [EMAIL PROTECTED] wrote:

Perhaps, but you never know: someone on this list may have a better
solution for your problem.

Mike

___
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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-06 Thread Ian Thomas

Whoops, sorry, missed your extra 'm' on 'mFooA' (not sure why that
crept in there?):
Object.registerClass(FooA, FooA);
var aObject:FooA_Class = _root.attachMovie(FooA, FooA, 1);

Ian

On 7/7/06, Ian Thomas [EMAIL PROTECTED] wrote:

Hi Julian,
  You were nearly there with:
Object.registerClass(mFooA, FooA);
var aObject:FooA_Class = _root.attachMovie(FooA, FooA, 1);

Just change it to:
Object.registerClass(mFooA, FooA);
var aObject:FooA_Class = FooA_Class(_root.attachMovie(FooA, FooA, 1));

(as Class(x) is the equivalent of the Java class cast operator (Class)x)

HTH,
  Ian

On 7/7/06, Mike Britton [EMAIL PROTECTED] wrote:
 Perhaps, but you never know: someone on this list may have a better
 solution for your problem.

 Mike


___
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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-06 Thread Ian Thomas

*sigh* Having a bad morning and copying the wrong line. Third time lucky:

Object.registerClass(FooA, FooA_Class);
var aObject:FooA_Class = FooA_Class(_root.attachMovie(FooA, FooA, 1));


Ian

On 7/7/06, Ian Thomas [EMAIL PROTECTED] wrote:

Whoops, sorry, missed your extra 'm' on 'mFooA' (not sure why that
crept in there?):
Object.registerClass(FooA, FooA);
var aObject:FooA_Class = _root.attachMovie(FooA, FooA, 1);

Ian

On 7/7/06, Ian Thomas [EMAIL PROTECTED] wrote:
 Hi Julian,
   You were nearly there with:
 Object.registerClass(mFooA, FooA);
 var aObject:FooA_Class = _root.attachMovie(FooA, FooA, 1);

 Just change it to:
 Object.registerClass(mFooA, FooA);
 var aObject:FooA_Class = FooA_Class(_root.attachMovie(FooA, FooA, 1));

 (as Class(x) is the equivalent of the Java class cast operator (Class)x)

 HTH,
   Ian

 On 7/7/06, Mike Britton [EMAIL PROTECTED] wrote:
  Perhaps, but you never know: someone on this list may have a better
  solution for your problem.
 
  Mike



___
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] Help for a Java Guy: Instantiating a MovieClip with a linked class and calling class methods

2006-07-06 Thread Julian Bleecker
Yeah, I think it gets worse. I'm used to a pattern where you create a  
whole bunch of something — so, back to the problem I originally  
asked, if I want have my mainClip create a dozen subClip instances  
and tuck each one of those instances in an Array for later use,  
especially calling that useful method. I guess I'm asking how one can  
call a method on an instance where the instance's name is derived at  
runtime.


For instance, in this example you provided, which works for the  
single subClip00 instance variable, how would I do the same thing,  
only with a runtime derived name?


class mainClip extends MovieClip
{
public var subClip00:subClip;

function mainClip() {
trace(new mainClip!);

init();
}

function init():Void {
for(int i=0; i12; i++) {
attachMovie(subClip, subClip_+i, 
this.getNextHighestDepth());
			//this.subClip00.usefulMethod(); this won't work..how to call a  
method with no reference — only a name?

}
}
}

But, the bigger question is: why don't things like attachMovie or  
such return references to the things they're attaching?


Julian

On Jul 6, 2006, at 20:50 PDT, Mike Britton wrote:


Perhaps, but you never know: someone on this list may have a better
solution for your problem.

Mike
___
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