Vishwas
Vishwas

Reputation: 1541

compiler error when trying to use addEventListener via interface

Trying to use addEventlistener with an interface, but i get a compiler error : => Call to a possibly undefined method addEventListener through a reference with static type IScene.

//IScene.as 

    public interface IScene 
        {

            function show():void

            function load():void;

            function unload():void;
        }

//Main.as
                    var scene:IScene  ;

        scene= sceneView_Arr[scene_number] ;


        scene.addEventListener( GameEvent.ON_LOAD_SCENE , start );
        scene.load();
        scene.show(); 

How should i achieve it then ?

Upvotes: 0

Views: 91

Answers (1)

Sam DeHaan
Sam DeHaan

Reputation: 10325

Instead of Fox in socks answer, I would recommend a slightly different approach:

public interface IScene extends IEventDispatcher

And then for your actual scene classes

public class MyScene extends EventDispatcher implements IScene

And then you can use it as you already have, without any additional code.

scene.addEventListener(GameEvent.ON_LOAD_SCENE, start);

Upvotes: 2

Related Questions