System对象
System对象是系统默认的对象,System对象包括系统函数和系统变量。
1.系统函数
系统函数包括:forEach()、getSystemTime()、callPhone()、sendSms()、getUrlParam()、setUrlParam()。
forEach()函数:其作用是在指定范围内查找到符合条件的对象。
例如:在舞台下查找id为pic的对象,并且输出其id、宽、高的属性。
System.forEach(
ids.stage,
function(obj){
return obj.id == "pic"
},
function(obj){
console.log(obj.id);
console.log(obj.width);
console.log(obj.height);
}
)
在舞台下查找文本内容为”123”的文本,并将其x坐标设置为200:
System.forEach(
ids.stage,
function(obj){ //查找的对象和条件
return obj.class == "mtext"&&obj.value="123"
},
function(obj){ //在控制后台输出对象的x坐标
obj.x=200
}
)
getSystemTime()函数:该函数可获取系统时间。
System.getSystemTime()
callPhone()函数:该函数可以拨打电话,参数为电话号码。
System.callPhone("XXXXXXXXXXX")
sendSms()函数:该函数可以发送短信,参数为电话号码。
System.sendSms("XXXXXXXXXXX")
getUrlParam()函数:该函数可获取网页参数
System.getUrlParam("aaa")
setUrlParam()函数:该函数可设置网页参数,记录对象的属性。
System.setUrlParam("aaa",ids.aa.value)
loadJs()函数:该函数可加载js外部库。
System.loadJs('http://xxx', function() {
console.log('done');
});
loadCss()函数:该函数可加载css外部库。
System.loadCss('http://xxx'\)
setTitle函数:改函数可设置网页标题。
System.setTitle();
2.系统变量
系统变量包括:deviceAlpha、deviceBeta、deviceGamma、userid、stageScale。
deviceAlpha:设备Z轴旋转
System.deviceAlpha
deviceBeta:设备x轴旋
System.deviceBeta
deviceGamma:设备y轴旋转
System.deviceGamma
输出 console.log(System)