Use code in the third part scripts

Find code here before you post.
Locked
support
Posts: 356
Joined: Sat Apr 27, 2013 9:22 am

Use code in the third part scripts

Post by support »

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);
            } );
        }
    }
});

Locked