Nope.

my_win, the variable, is still declared (to the compiler) as a MovieClip. It
only knows about it as type MovieClip.

The object it 'points to' happens to be of type MyCustomForm, which is an
object that inherits from MovieClip. It does all the things that MovieClip
does, just does more stuff too.

>From a compiler perspective, you can get away with calling methods of
MyCustomForm on your my_win _only because_ MovieClip is a dynamic class, and
so the compiler throws away all type-checking for my_win. It does mean that
anything you call on my_win will not be properly type checked.

If you had used a non-dyamic class in your example, the problem would have
become a lot more obvious. For example:

class A
{
public function doSomething() {trace("Do Something");}
}

class B extends A
{
public function doSomethingElse() {trace("Do Something Else");}
}

var my_a:A;

my_a=B(createBSomeHow()); // The compiler will choke on this line

my_a.doSomething(); // Compiler will be fine with this
my_a.doSomethingElse(); // Compiler would choke on this

or if it was:
var my_a:A;
my_a = A(createBSomeHow()); // Perfectly legal 'cos B inherits from A

my_a.doSomething(); // No problems
my_a.doSomethingElse(); // Compiler chokes, because it only knows that 'a'
is an A.


So in short - you can do exactly what you wrote down, but:
- Only because MovieClip is a dynamic class
- You're skipping compiler type-checking because MovieClip is a dynamic
class (so any type-signatures of methods of MyCustomForm you call will be
unchecked - which might be an issue if you, for example, went back and
redefined them later)
- You aren't actually changing the type of my_win. It's still a MovieClip,
as far as the compiler can see.

Cheers,
Ian

On 10/31/05, JesterXL <[EMAIL PROTECTED]> wrote:
>
> >>>You can't change the type of a variable during an assignment
>
> Yes you can.
>
> var my_win:MovieClip;
>
> my_win = MyCustomForm(PopUpManager.createPopUp(this, MyCustomForm,
> false));
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to