• Egret 使用遇到的问题总结(一)


    一:判断对象是否已经被添加到显示列表上

    1.类是否被加载到舞台:egret.Evetn.ADD_TO_STAGE      
    2.判断对象是否被添加到父容器里:father.contains(child):Boolean
    3.this.stage!=null (this是判断的对象类)

     二:egret调用原生js实现复制功能

    //str:复制的内容
    public setTextToClipboard(str: string) {
                var input = document.createElement("input");
                input.value = str;
           input.readOnly = true; //在ios上必须加上 document.body.appendChild(input); input.
    select(); input.setSelectionRange(0, input.value.length), document.execCommand('Copy'); document.body.removeChild(input); // window.alert("复制成功"); EffectUtils.showTips("房间信息已经复制成功,请粘贴发送给好友"); }

     三:egret使用 egret.localStorage出现的问题

    什么是localStorage
    在HTML5中,新加入了一个localStorage特性,这个特性主要是用来作为本地存储来使用的,解决了cookie存储空间不足的问题(cookie中每条cookie的存储空间为4k),localStorage中一般浏览器支持的是5M大小,这个在不同的浏览器中localStorage会有所不同。

    localStorage的优势
    1、localStorage拓展了cookie的4K限制
    2、localStorage会可以将第一次请求的数据直接存储到本地,这个相当于一个5M大小的针对于前端页面的数据库,相比于cookie可以节约带宽,但是这个却是只有在高版本的浏览器中才支持的
    3、localStorage与sessionStorage的唯一一点区别就是localStorage属于永久性存储,而sessionStorage属于当会话结束的时候,sessionStorage中的键值对会被清空

    localStorage的使用
    localStorage.getItem(key):获取指定key本地存储的值
    localStorage.setItem(key,value):将value存储到key字段

    存:egret.localStorage.setItem('test','string');
    取:egret.localStorage.getItem('test');
    删:egret.localStorage.removeItem('test');
    清空所有:egret.localStorage.clear();
    
    存:egret.localStorage.setItem('test', JSON.stringify(data));
    取:var data = JSON.parse(<string>egret.localStorage.getItem('test'));
    删:egret.localStorage.removeItem('test');
    清空所有:egret.localStorage.clear();

     egret.localStorage在使用setItem存储数据后,浏览器会一直记住上一次存储的数据,当要改动的时候需要先清除 removeItem对应的字段,或者清空所有 clear();在用setItem存储。

    四:判断是不是微信上浏览

        //是不是微信浏览
        export function isWeiXin(): boolean
        {
            var ua = window.navigator.userAgent.toLowerCase();
    
            var microStr = "" + ua.match(/MicroMessenger/i);
    
            if(microStr == "null")
            {
                return false;
            }
            else if(microStr == "micromessenger")
            {
                return true;
            }
        }

     五:选中一组按钮其中一个,并且需要处理选中和非选中的区别

    let index: number = this.btnList.indexOf(e.target);
    for(let i = 0; i < this.btnList.length; i++) {
        if (i == index) {
             this.btnList[I].y = 100;
         }else{
             this.btnList[I].y = 0;
        }
    }        

     六:egret 判断是native还是web端

    egret.Capabilities.runtimeType ?

    webegret.RuntimeType.WEB

    native egret.RuntimeType.NATIVE

    移动设备打开egret.Capabilities.isMobile或者 window.innerHeight =? window.innerWidth
    山重水复疑无路,柳暗花明又一村! 专注填坑,少走弯路!
  • 相关阅读:
    笔记本越用越慢的解决方法。
    ubuntu 16.04 的IP地址变更
    如何把路由器当作交换机来使用
    通过 rufus 创建启动U盘,安装 VMWare Esxi
    Enable SMB2 on the Client
    Shiro入门学习与实战(一)
    Linux下Nginx1.9.9的安装
    Activiti工作流学习之SpringBoot整合Activiti5.22.0实现在线设计器(二)
    Activiti工作流学习之概述(一)
    Sqoop的安装及常用命令
  • 原文地址:https://www.cnblogs.com/mqflive81/p/12395579.html
Copyright © 2020-2023  润新知