Use code in the third part scripts

Find code here before you post.

Use code in the third part scripts

Postby support » Mon Mar 11, 2019 6:05 pm

Suppose you have a script like this ( in ThirdPart/scripts/myscript.js ):

javascript code
// An unique namespace is important
MyScript={};

MyScript.User = function(name){
this.name = name || "No Name";
};
MyScript.User.prototype.sayHi = function (msg){
alert("To " + this.name + ": " + (msg||"Hi") );
};


You can include and call the inner functions :

javascript code
xui.Class('App', 'xui.Module',{
Instance:{
iniComponents : function(){
// [[Code created by CrossUI RAD Studio
var host=this, children=[], append=function(child){children.push(child.get(0));};

append(
xui.create("xui.UI.HTMLButton")
.setHost(host,"xui_ui_htmlbutton2")
.setLeft("4.166666666666667em")
.setTop("3.3333333333333335em")
.setCaption("Say Hi to John")
.onClick("_xui_ui_htmlbutton2_onclick")
);

return children;
// ]]Code created by CrossUI RAD Studio
},
_xui_ui_htmlbutton2_onclick:function(profile, e, src){
// 'MyScript.User' must be the unique namespce in myscript.js, it can be cached by this id whe you first call it
// Though, if you call xui.include it again, the system will get it from cache, won't get it from the script again
xui.include('MyScript.User','ThirdPart/scripts/myscript.js', function() {
var john = new MyScript.User("John");
john.sayHi("Hello!");
}, function(err) {
xui.alert('fail:' + err);
} );
}
}
});
support
 
Posts: 352
Joined: Sat Apr 27, 2013 9:22 am

Return to CrossUI Code Snaps

Who is online

Users browsing this forum: No registered users and 2 guests

cron