0
votes

I'm working on a project and I've extended Stage (I just wanted to add one function).

Anyway, I created a new Stage class (let's call it StageX) and I had a line of code like this:

var newstage:StageX = stage;

But this gives me the implicit coercion error.

My question is, is there a way of copying everything from the current stage var into the new StageX? Or do I need to create a new "convertToStageX" function and do it myself? Or is there no use in extending the Stage because it's an integral part of flash?

Thanks!

2
Just spit out an often used property. I'd pass a dimenion (x or y) and a width of an object. It'd give me the top-left x and y i'd need that'd make the object perfectly centered; it'll change shape and size a lot - Keith Larson

2 Answers

0
votes

I can not see any reason why you would want to extend stage. You could just create an object that has a reference to stage that has methods that you can call, and would affect the stage somehow. This would encapsulate the functionality and keep you from messing around with the actual stage.

0
votes

Try:

var newstage:StageX = StageX(stage); // throws an error if the cast is not possible

Or

var newstage:StageX = stage as StageX; // new stage is null if the cast is not possible