PDA

View Full Version : IEVentDispatcher compile error



delta3d
March 26th, 2008, 02:35 AM
Dear All,

I encounter one problem when use IEVentDispatcher/EVentDispatcher, it gives out below error:
com\icutommy\events\IEventDispatcher.as: the third line: class definition not allowed in this statement, _global.com.icutommy.events.IEventDispatcher = function ()

Woud you some one give me some advise, thanks a million!

The code of IEVentDispatcher:

class com.icutommy.events.IEventDispatcher
{
_global.com.icutommy.events.IEventDispatcher = function ()
{
};
} // End of Class

The code of EVentDispatcher:


class com.icutommy.events.EventDispatcher implements com.icutommy.events.IEventDispatcher
{
var _ls;
function EventDispatcher()
{
this.init();
} // End of the function
function addEventListener(e, l, f)
{
for (var _loc2 in _ls)
{
if (_ls[_loc2].e == e && _ls[_loc2].l == l)
{
return (false);
} // end if
} // end of for...in
_ls.push({e: e, l: l, f: f});
return (true);
} // End of the function

function removeEventListener(e, l)
{
for (var _loc2 = 0; _loc2 < _ls.length; ++_loc2)
{
if (_ls[_loc2].e == e && _ls[_loc2].l == l)
{
_ls.splice(_loc2, 1);
return (true);
} // end if
} // end of for
return (false);
} // End of the function
function dispatchEvent(ev)
{
for (var _loc3 in _ls)
{
if (_ls[_loc3].e == ev.type)
{
if (_ls[_loc3].f)
{
_ls[_loc3].f.apply(_ls[_loc3].l, [ev]);
continue;
} // end if
_ls[_loc3].l[ev.type](ev);
} // end if
} // end of for...in
} // End of the function
function clear()
{
_ls = new Array();
} // End of the function
function destroy()
{
this.clear();
delete this._ls;
} // End of the function

function init()
{
_ls = new Array();
} // End of the function
} // End of Class

icio
March 26th, 2008, 12:12 PM
Perhaps you are wanting to do this:

package com.icutommy.event {
public class IEventDispatcher {
function IEventDispatcher ()
{ }
} // End of Class
}

?? :-/

Oh wait -- are you using AS3 or AS2 ?

delta3d
March 27th, 2008, 12:18 AM
I am using AS2,and I have solved the problem with interface,Thanks!

icio
March 27th, 2008, 07:42 AM
Sorry about that. I realised after I had written my reply that the syntax was AS2 and I don't know much about it's class structure.

Glad you got it sorted, though.