actionscript 3 – Recasting member of a library class to new type in extended class – Education Career Blog

I created an flv video player using Flash Builder 4. This “BasicVideoPlayer” project is compiled into a SWC that will be eventually be used to create other video players that extend the functionality. One of the features is a view that appears when the video has finished playing that displays a “Play Again” button. This “Play Again” view has its own class, “BasicPlayAgain”, that accepts a graphic asset that is exported from a .fla file that contains all of the graphic/UI assets.

In my new project, “EnhancedVideoPlayer”, I’m using the BasicVideoPlayer SWC as a library to create a new video player that will add more functionality to the “Play Again” view; specifically it will add more buttons to that view.

The EnhancedVideoPlayer uses a default class that extends the BasicVideoPlayer class. The BasicVideoPlayer class has a member called “playAgainScreen” whose type is BasicPlayAgain. The EnhancedVideoPlayer needs to override the playAgain member and recast it as EnhancedPlayAgain so it can control the new buttons properly.

How do I go about overriding the playAgain member as a new type? Or am I approaching this from the wrong direction?

,

One possible solution is if the EnhancedPlayAgain object extends BasicPlayAgain, you could still store it in the playAgainScreen variable, and then cast back to EnhancedPlayAgain as needed.

EnhancedPlayAgain(playAgainScreen).someAdditionalMethod();

Leave a Comment