Re: [Flashcoders] as2 - method losing scope when called from timeline.

2008-06-25 Thread Joseph Balderson
AS2 is full of mysterious crap, er bugs like this. It's what made Flash such a 
pain at times. I am s loving AS3... not that it's without it's own "quirks"...


___

Joseph Balderson, Flash Platform Developer | http://joeflash.ca


Steven Sacks wrote:

It's a "rare" bug that is unacknowledged by Macromedia/Adobe.

If you name the package folder that contains your class the same as your 
class name (case doesn't matter), AS2 will behave like a dumbass.  It 
does randomly buggy behavior, and it's impossible to track down what it 
is because there's nothing wrong with your code, it's AS2 being buggy.


Once you rename your package or class, everything works as it should.


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] as2 - method losing scope when called from timeline.

2008-06-23 Thread Steven Sacks


Also, I'm not sure what you are trying to do with 'this.clip = clip;', 
but you cannot instantiate or associate a MovieClip inside an Object 
(which Test is), and have successful access to its properties and 
methods.
He's using composition, which is sometimes preferable to extending 
MovieClip in AS2. He's passing a reference to the MovieClip in the 
constructor.


However, I generally avoid having MovieClips themselves instantiate 
their class on their own timeline, however, because then it's not 
explicit anywhere else what's going on and then you have to dig through 
the MovieClips to find out where code is (timeline code can be a major 
pain).  In those cases, you should either have a controller class do 
that or extend MovieClip and assign the class to the clip in the libary.


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] as2 - method losing scope when called from timeline.

2008-06-23 Thread Steven Sacks

It's a "rare" bug that is unacknowledged by Macromedia/Adobe.

If you name the package folder that contains your class the same as your 
class name (case doesn't matter), AS2 will behave like a dumbass.  It 
does randomly buggy behavior, and it's impossible to track down what it 
is because there's nothing wrong with your code, it's AS2 being buggy.


Once you rename your package or class, everything works as it should.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] as2 - method losing scope when called from timeline.

2008-06-23 Thread Steven Sacks


Because of the way everything in AS2 is centred around the MovieClip 
class, in order to create any kind of MVC architecture, which I gather 
you are trying to do, it's all about the MovieClip. You can have your 
Model be an Object, but your View and Controller classes, and any 
other visual display class need to be MovieClips, as a general rule.
Unless you use composition and pass a reference to a MovieClip in the 
constructor.  ;)

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] as2 - method losing scope when called from timeline.

2008-06-23 Thread Joseph Balderson

My first though is that you would have your class structure as:
/[ClassTest].fla
/test/Test.as
/test/Model.as

But that would give you a compiler error, because you're not importing Model. So 
you must be using

/[ClassTest].fla
/test/Test.as
/Model.as

Here's the files I am using;

/Test_class_scope.fla : (same as you described)
---
import test.Test;
var test:Test = new Test(this);
test.init( );

/test/Test.as : (same as you described)
---
class test.Test
{

private var m:Model;
private var clip:MovieClip;

function Test(clip:MovieClip)
{
this.clip = clip;
trace ("test");
trace (this instanceof Test);
}
public function init():Void
{
trace (this instanceof Test);
m = new Model();
trace ("m = " + m);
}
}

/Model.as :

class Model
{
function Model()
{
trace("Model instantiated");
}
}


And the trace I get is:

test
true
false
Model instantiated
m = [object Object]

...but when I change your timeline code to this:

import test.Test;
var classTest:Test = new Test(this);
classTest.init( );

...the trace I get is:

test
true
true
Model instantiated
m = [object Object]

The reason for this is that in AS2, type checking occurs at compile-time, not at 
runtime, so when the code is run, there are a few things that can get 
potentially confused:

- your instance name is 'test'
- your package name is 'test'
- your class name is 'Test'

All of which may look to be all the same at runtime. I'm surprised this runs, 
frankly. If it were in a more complex application you would most likely get 
runtime errors which would be extremely hard to track down.


In AS3 there is runtime type checking, and the runtime would not get confused, 
and know that 'test' and 'Test' are different, or throw an error. As it is the 
AS2 runtime has loose type checking, and does not detect anything amiss, but you 
get unpredictable results.


My advice would be to use best practises, and keep package names, class names 
and instance names unique.


Tracing (or type checking) a Model instance or any other custom class for that 
matter will always return a type of 'object' in AS2; you need to use 
'instanceof' to determine the class. (m instanceof Model) will return true. In 
AS3 there are far better tools, such as parsing the describeType() XML output.


Also, I'm not sure what you are trying to do with 'this.clip = clip;', but you 
cannot instantiate or associate a MovieClip inside an Object (which Test is), 
and have successful access to its properties and methods. MovieClips in AS2 are 
these weird hybridized creatures: not quite built-in objects, not quite OOP 
objects. You would have to declare 'class Test extends MovieClip', and 
associate the test class with a clip in the library and instantiate that symbol 
on the timeline at authortime, or at runtime with createEmptyMovieClip(). Other 
runtime-instantiated classes will need to be associated with an MC library 
symbol, instantiated from Test via createEmptyMovieClip().


Because of the way everything in AS2 is centred around the MovieClip class, in 
order to create any kind of MVC architecture, which I gather you are trying to 
do, it's all about the MovieClip. You can have your Model be an Object, but your 
View and Controller classes, and any other visual display class need to be 
MovieClips, as a general rule.


___

Joseph Balderson, Flash Platform Developer | http://joeflash.ca


paul cunningham wrote:

If I have this on the flash timeline, (CS3 or Flash 8)

import test.Test;
var test:Test = new Test(this);
*test.init( );*

--

and then the class code has this

class test.Test
{

private var m:Model;
private var clip:MovieClip;

function Test(clip:MovieClip)
{
this.clip = clip;
trace ("test");
trace (this instanceof Test);
}
public function init():Void
{
trace (this instanceof Test);
m = new Model();
trace ("m = " + m);
}

--
it traces:
test
true
false
m =

--

but if I the init call originates from the constructor, instead of from the
main timeline, ie
function Test(clip:MovieClip)
{
this.clip = clip;
trace ("test");
trace (this instanceof Test);
*init( );*
}

it traces:

test
true
true
m = [object Object]

--

does anyone know why the "m" value disappears when the init method is called
from the timeline?
.

Thanks in advance.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.co

Re: [Flashcoders] as2 - method losing scope when called from timeline.

2008-06-23 Thread Cor
Tr ythis

import test.Test;
// old:var test:Test = new Test(this);
var test:Test = new Test();
test.init( );

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] as2 - method losing scope when called from timeline.

2008-06-23 Thread Jason Van Cleave
you should get compiler errors over this but did you import Model?

On Mon, Jun 23, 2008 at 8:24 AM, Paul Evans <
[EMAIL PROTECTED]> wrote:

> untested suggestion?!...
>
> On 23 Jun 2008, at 10:20, paul cunningham wrote:
>
>> If I have this on the flash timeline, (CS3 or Flash 8)
>> import test.Test;
>> var test:Test = new Test(this);
>> *test.init( );*
>>
>
> is test (the variable) being confused with test (the package) ?
>
> my next step would be to try this again using a different variable name.
>
> --
> Paul Evans
> http://www.creative-cognition.co.uk/
> http://blog.creacog.co.uk/
>
>
> ___
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] as2 - method losing scope when called from timeline.

2008-06-23 Thread Paul Evans

untested suggestion?!...

On 23 Jun 2008, at 10:20, paul cunningham wrote:

If I have this on the flash timeline, (CS3 or Flash 8)
import test.Test;
var test:Test = new Test(this);
*test.init( );*


is test (the variable) being confused with test (the package) ?

my next step would be to try this again using a different variable name.

--
Paul Evans
http://www.creative-cognition.co.uk/
http://blog.creacog.co.uk/

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] as2 - method losing scope when called from timeline.

2008-06-23 Thread paul cunningham
If I have this on the flash timeline, (CS3 or Flash 8)

import test.Test;
var test:Test = new Test(this);
*test.init( );*

--

and then the class code has this

class test.Test
{

private var m:Model;
private var clip:MovieClip;

function Test(clip:MovieClip)
{
this.clip = clip;
trace ("test");
trace (this instanceof Test);
}
public function init():Void
{
trace (this instanceof Test);
m = new Model();
trace ("m = " + m);
}

--
it traces:
test
true
false
m =

--

but if I the init call originates from the constructor, instead of from the
main timeline, ie
function Test(clip:MovieClip)
{
this.clip = clip;
trace ("test");
trace (this instanceof Test);
*init( );*
}

it traces:

test
true
true
m = [object Object]

--

does anyone know why the "m" value disappears when the init method is called
from the timeline?
.

Thanks in advance.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders