Sunday, May 27, 2012

[Action Script] Casting an Object? May,2012

I remember reading a long time ago that when one wishes to give an instance a different class for whatever reason, it's called casting... at least I think so.

Anyways, I'm new here. Hello All. :) And I'm already encountering some difficulties. This one is one that I simply do not know how to fix.

The Attractor class is extended from MovieClip. There is an attractor instance as a child of the stage named "attractor".

Code: if (stage.getChildByName("attractor") != null)
                        {
                                var attractor:Attractor = (stage.getChildByName("attractor"));
                        }The problem with this is:
Code: Implicit coercion of a value with static type flash.display:DisplayObject to a possibly unrelated type Attractor.I can't afford to just make the variable type Object, because I'm going to use the reference as an argument in other methods.

Can anybody tell me how to fix this? I'm sure it's an easy fix. I substantially cleaned the code, if you need to see more just say.
Casting an Object?

Related Post



0 comments: