views:

735

answers:

4

Hello all,

I have an activex object I loaded into an html page. I then use that activex object to create another object, but I need to register an event with the new object created. The object is expecting an event listener of a certain type.

I can load this same dll in c# and it will work fine. Code looks like this for c#.

upload = obj.constructUploadObj(uploadConfig);
upload.stateChanged += new UploadActionEvents_stateChangedEventHandler(upload_stateChanged);

In javascript I have similar code however I cannot get the event registered with the object.

uploadAction = obj.constructUploadObj(uploadConfig);
uploadAction.stateChanged = upload_stateChanged;

function upload_stateChanged(sender){
    writeLine("uploadState changed " + sender.getState());
}

I have enumerated some of the properties of the uploadAction object in javascript to ensure that it is actually created. When I try and register the event with uploadAction it throws an error saying "Object doesn't support this property or method."

To me it seems like its expecting a strongly typed event. Is there anyway to register the event similar to that of C# in javascript?

Thanks In Advance.

A: 

Your javascript should look something like this:

function uploadAction::stateChanged( parms )
{
    // ...
    // implementation
    // ...
}

Note, that this is a static function declaration, assuming that you have an Active X object named 'uploadAction'. I know that this does work - we use it at my company.

Adam
If I try writing a function like that in my JS it completely crashes.
JustFoo
The uploadAction is not the activex object. The activex object lets say axObj has a construct function axObj.constructUpload which creates the uploadAction object. I called a function on uploadAction after its created to verify something is there.
JustFoo
A: 

The error message means that uploadAction does not support stateChanged property. Your javascript code looks correct, the problem seems to be with the object you are trying to attach an event handler to.

When I load the dll in VS 2005 and reference the upload object created in c# the stateChanged property comes up as an event that I can assign a handler function to. As shown from the code above.
JustFoo
A: 

I'd suggest using the andvanced event registration model outlined here.

uploadAction.addEventListener('stateChanged', upload_stateChanged, false);

note, you may need to interrogate your arguments for the upload_stateChanged method, as the first argument should be the event state. ex: upload_stateChanged(evt, sender) ...

Tracker1
A: 

Found out from the company that these properties are not accessible through javascript. They will need to externalize them for use within javascript.

JustFoo