单纯的记录,不是学习过程,用到了什么就记什么了
【报错】编译过程出现 Not allowed to load local resource:
原因是使用资源的时候使用了路径来添加,比如F:xxx/xxxx/icon.png,这样的话就会无法加载资源,正确做法应该是使用资源名字,如 icon_png
点击事件
protected onTouchTap(e) {
// console.log("onTouchTap---");
switch (e.target) {
case this.Back: // 定义的UI的名字
console.log("返回");
break;
}
}
// ---------------------------------------------------------------
// 先添加事件监听
this.addEventListener(egret.TouchEvent.TOUCH_END, this.onTouchEnd, this, true);
// 抬手触发
protected onTouchEnd(e) {
}
scroller
// scroller的滑动事件监听
this.Scroller.addEventListener(egret.Event.CHANGE, this.onScrollerChange, this);
this.Scroller.addEventListener(eui.UIEvent.CHANGE_END, this.changeEndDo, this);
private onScrollerChange() {
// 滑动都会触发
}
private changeEndDo() {
// 滑动结束触发
}
// ---------------------------------------------------------------
// 锁定scroller滑动
this.Scroller.scrollPolicyV = eui.ScrollPolicy.OFF;
// 解锁
this.Scroller.scrollPolicyV = eui.ScrollPolicy.ON;
// ---------------------------------------------------------------
// 关闭scroller滑动动画
// 可以滑动但是不会有动画效果
this.Scroller.stopAnimation();
List
// list在scroller下,需要移除其中一个元素想让后面的元素填充上来时,要在移除之后使用refresh()
// this.List.dataProvider = this.ArrayCollection;
this.ArrayCollection.removeItemAt(index);
this.ArrayCollection.refresh();
// 如果在一个长度40的数组中,想移除前20个,又不想让后面的index自动跟进,则可以倒序移除,即
for (var i = 20; i >0; i--) {
this.ArrayCollection.removeItemAt(i);
}
// 如果进行正序移除的话,会出现这种情况
Tween
egret.Tween.get(this.ItemList) // 获取tween的对象
.wait(1000) // 延时等待一秒钟
.to({}) // 位置/选择/缩放等等属性变换
.call(() => { // 回调
egret.Tween.removeTweens(this.ItemList); // 执行完之后移除这个对象的tween
});
egret.Tween.get(this.ItemList, { loop: true }) // 打开循环
.to({ rotation: 360 }, 500); // 每0.5秒执行一次旋转360,循环执行
Exml中的对象属性
如果想对exml中的对象进行操作,如位移,那么该属性需要进行
解锁
,如图,属性是灰色,个人认为类似于锁定状态,不可对该属性进行操作,不知道官方是怎么说明这个状态.
遮罩
这里记录一个坑,给Group盖上一个遮罩时,Group内部的点击事件怎么也触发不了,设置touchEnable为false也不行,
解决方法是遮罩的visible要为true,遮罩图层隐藏时会挡住点击事件
Index.html
项目的index里有这么一句
window.scrollTo(0,0)
,意味加载时页面回到顶部
这个api也可以使页面滚动到指定位置
然而有个坑是打包时发布web,发现web项目里的index里面并没有这一句,导致出现了页面滚动到底部之后刷新,会使要显示的内容的顶部刷新在现在的位置,如图.浏览器上面空出一大部分空白
解决方法是在发布完web项目的index.html加上这一句window.scrollTo(0,0)
就好了
在Index.html的中可以使用
// 监听窗口尺寸改变
window.onresize=function(){
// 网页重新加载或者其他操作
location.reload();
}
// 或者
window.onresize = autodivheight;
autodivheight();
// 或者
window.addEventListener('resize', e => { this.getHeight(); }, false);
function getHeight() {}
window.open(url)
window.open(url)是新打开一个标签页
window.open(url,"_self")是当前网页跳转