Monday, March 26, 2012

Access class from inline frame

I have a composite control with associated javascript. The javascript uses registerClass to register a class. What I'd like to be able to do is access a method in this class from outwith my control, from another frame to be specific. Normally I'd simply do parent.class.method but when I try that I get a "not a function" error. When I try alerting the class I get the javascript code for it and not the instance.

So how do I get the instance of the class registered with registerClass from within another frame, if it is at all possible.

Thanks.

Hi

Would you please provide us with your code,so we can reproduce this issue quicklier?

Thanks


Thanks for the reply.

This is the javascript code for the control, I have snipped some of the functions to cut the length.

Type.registerNamespace('number45');

number45.editor = function(element) {

number45.editor.initializeBase(this, [element]);

this.type = 'editor';
this.editor_obj_id = '';
this.toolbar_id = '';
this.colors = '';

this.popups = new Array();
this.buttons = new Array();
this.popupshowing = '';
};

number45.editor.prototype = {

initialize: function()
{
number45.editor.callBaseMethod(this, 'initialize');

this.editor_obj = document.getElementById(this.editor_obj_id);

var documentClick = Function.createDelegate(this, this.close);
$addHandler(document, 'click', documentClick);
},

dispose : function() {
$clearHandlers(this.get_element());

number45.editor.callBaseMethod(this, 'dispose');
},

get_editor_obj_id: function()
{
return this.editor_obj_id;
},

set_editor_obj_id: function(value)
{
this.editor_obj_id = value;
},

insertText : function(newtext) {
this.checkFocus();
if (document.selection)
document.selection.createRange().text = newtext;
else {
if (typeof(this.editor_obj.selectionStart) != 'undefined') {
this.editor_obj.value = this.editor_obj.value.substr(0, this.editor_obj.selectionStart) + newtext + this.editor_obj.value.substr(this.editor_obj.selectionEnd, this.editor_obj.value.length);
} else {
this.editor_obj.value += newtext;
}
}
},

insertAttachment : function(attachment) {
var start_tag = '[image]';
var end_tag = '[/image]'

this.insertText( start_tag + attachment + end_tag );
},

}

number45.editor.registerClass('number45.editor', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

function stop_bubble(obj) {
if (!obj) {
window.event.cancelBubble=true;
return window.event;
} else {
obj.stopPropagation();
return obj;
}
};

It is the functioninsertAttachment I want to call from the inline frame. I have tried usingparent.number45.editor.insertAttachment('x'), this is what causes the 'not a function' error. When I try alertingparent.number45.editor I get the body of thefunction(element) shown.

No comments:

Post a Comment