<sdt id="89512093" sdtlocked="t" contentlocked="t" sdtgroup="t"></sdt>

Fixjs介绍

Fixjs是我打算在javascript技术领域开始积累的一个框架项目,这套框架主要为开发复杂组件提供底层的框架支持。

框架的类与接口我会尽量参考flash框架的实现。同时,我也会开放Fixjs的源代码,欢迎同仁一起学习、交流。

DisplayObjectContainer

DisplayObjectContainer是显示容器基类,它提供了显示子项的添加、移除、层次控制等接口。以下是代码实现:

fixjs.display.DisplayObjectContainer = fixjs.display.InteractiveObject.extend({

init: function (ele) {

fixjs.display.DisplayObjectContainer.base.init.call(this, ele);

this.mouseChildren = true;

this.numChildren = 0;

this.tabChildren = true;

this._children = [];

},

disposing:function () {

this.numChildren = 0;

fixjs.DisposeUtil.dispose(this._children);

this._children = null;

fixjs.display.DisplayObjectContainer.base.disposing.call(this);

},

setMouseChildren: function(value) {

var array = this._children;

for (var i = 0; i < array.length; i++) {

var child = array[i];

child.mouseEnabled = value;

if (child instanceof fixjs.display.DisplayObjectContainer) {

child.setMouseChildren(value);

}

}

},

setTabChildren: function(value) {

var array = this._children;

for (var i = 0; i < array.length; i++) {

var child = array[i];

child.tabEnabled = value;

if (child instanceof fixjs.display.DisplayObjectContainer) {

child.setTabChildren(value);

}

}

},

addChild: function(child) {

if (!(child instanceof fixjs.display.DisplayObject))

throw new Error("[ArgumentError]child必须是fixjs.display.DisplayObject类型!");

if (child == this)

throw new Error("[ArgumentError]child不能添加到自身!");

if (child.parent!= null)

throw new Error("[ArgumentError]child.parent不为空!");

if (this.contains(child))

throw new Error("[ArgumentError]已经包含child!");

this.ele.appendChild(child.ele);

child.parent = this;

this.numChildren++;

this._children.push(child);

var e = new fixjs.events.Event(fixjs.events.Event.ADDED);

this.dispatchEvent(e);

},

addChildAt: function(child, index) {

if (!(child instanceof fixjs.display.DisplayObject))

throw new Error("[ArgumentError]child必须是fixjs.display.DisplayObject类型!");

if (child == this)

throw new Error("[ArgumentError]child不能添加到自身!");

if (child.parent!= null)

throw new Error("[ArgumentError]child.parent不为空!");

if (this.contains(child))

throw new Error("[ArgumentError]已经包含child!");

if (index < 0 || index>= this.numChildren)

throw new Error("[RangeError]索引超出范围!");

var prev = this._children[index];

this.ele.insertBefore(child.ele, prev.ele);

child.parent = this;

this.numChildren++;

this._children.splice(index, 0, child);

var e = new fixjs.events.Event(fixjs.events.Event.ADDED);

this.dispatchEvent(e);

},

contains:function (child) {

var array = this._children;

return array.indexOf(child)>= 0;

},

getChildAt: function(index) {

if (index < 0 || index>= this.numChildren)

throw new Error("[RangeError]索引超出范围!");

return this._children[index];

},

getChildByName: function(name) {

var array = this._children;

for (var i = 0; i < array.length; i++) {

var child = array[i];

if (child.name== name)

return child;

}

},

getChildIndex: function(child) {

var i = this._children.indexOf(child);

if (i< 0)

throw newError("[ArgumentError]child不是该对象的子项!");

return i;

},

removeChild: function(child) {

var i = this._children.indexOf(child);

if (i< 0)

throw newError("[ArgumentError]child不是该对象的子项!");

return this.removeChildAt(i);

},

removeChildAt: function(index) {

if (index < 0 || index>= this.numChildren)

throw new Error("[RangeError]索引超出范围!");

var child = this._children[index];

this.ele.removeChild(child.ele);

this.numChildren--;

this._children.splice(index, 1);

var e = new fixjs.events.Event(fixjs.events.Event.REMOVED);

this.dispatchEvent(e);

return child;

},

removeAllChildren: function() {

var e;

if (this.numChildren)

e = new fixjs.events.Event(fixjs.events.Event.REMOVED);

while (this._children.length) {

var child = this._children.pop();

this.ele.removeChild(child.ele);

child.dispose();

}

this.numChildren = 0;

if (e)

this.dispatchEvent(e);

},

setChildIndex: function(child, index) {

if (index < 0 || index>= this.numChildren)

throw new Error("[RangeError]索引超出范围!");

var i = this._children.indexOf(child);

if (i< 0)

throw new Error("[ArgumentError]child不是该对象的子项!");

if (i== index)

return;

this._children.splice(i, 1);

this.ele.removeChild(child.ele);

if (index < this._children.length) {

var prev = this._children[index];

this.ele.insertBefore(child.ele, prev.ele);

}

else {

this.ele.appendChild(child.ele);

}

this._children.splice(index, 0, child);

},

swapChildren: function(child1, child2) {

var i1 = this._children.indexOf(child1);

if (i1 < 0)

throw new Error("[ArgumentError]child1不是该对象的子项!");

var i2 = this._children.indexOf(child2);

if (i2 < 0)

throw new Error("[ArgumentError]child2不是该对象的子项!");

var t1 = child1.ele.nextSibling;

var t2 = child2.ele.nextSibling;

if (t1)

this.ele.insertBefore(child2.ele, t1);

else

this.ele.appendChild(child2.ele);

if (t2)

this.ele.insertBefore(child1.ele, t2);

else

this.ele.appendChild(child1.ele);

},

swapChildrenAt: function(index1, index2) {

if (index1 < 0 || index1>= this.numChildren)

throw new Error("[RangeError]索引index1超出范围!");

if (index2 < 0 || index2>= this.numChildren)

throw new Error("[RangeError]索引index2超出范围!");

var child1 = this._children[index1];

var child2 = this._children[index2];

this.swapChildren(child1, child2);

}

});

相关文章

Fixjs专栏

Fixjs——显示容器基类DisplayObjectContainer相关推荐

  1. Fixjs——显示交互基类InteractiveObject

    <sdt id="89512093" sdtlocked="t" contentlocked="t" sdtgroup="t ...

  2. Fixjs——显示基类DisplayObject

    <sdt id="89512093" sdtgroup="t" contentlocked="t" sdtlocked="t ...

  3. 编写一个制造各种车辆的程序。包含三个类,具体要求如下: (1)基类Vehicle,包含轮子数和汽车自身重量两个属性,一个两参数的构造方法,一个显示汽车信息的方法; (2)小轿车类Car,增加载客数属性

    一.题目描述 编写一个制造各种车辆的程序.包含三个类,具体要求如下: (1)基类Vehicle,包含轮子数和汽车自身重量两个属性,一个两参数的构造方法,一个显示汽车信息的方法: (2)小轿车类Car, ...

  4. 稳扎稳打Silverlight(8) - 2.0图形之基类System.Windows.Shapes.Shape

    [索引页] [×××] 稳扎稳打Silverlight(8) - 2.0图形之基类System.Windows.Shapes.Shape 作者:webabcd 介绍 Silverlight 2.0 图 ...

  5. 使用P/Invoke来开发用于与串行设备通讯的.NET基类

    这篇文章可以帮助你熟悉于用C#开发与RS232的通讯. 难易程度 1.2.3   本文相关代码下载:NetSerialComm.exe (89KB) http://download.microsoft ...

  6. C++ 多继承类 虚基类

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/jzj_c_love/article/d ...

  7. Python学习笔记28:从协议到抽象基类

    Python学习笔记28:从协议到抽象基类 今后本系列笔记的示例代码都将存放在Github项目:https://github.com/icexmoon/python-learning-notes 在P ...

  8. [cb]NGUI组件基类之 UIWidget

    UIWidget NGUI的UIWidget是所有组件的基类,它承担了存储显示内容,颜色调配,显示深度,显示位置,显示大小,显示角度,显示的多边形形状,归属哪个UIPanel.这就是UIWidget所 ...

  9. Java记录 -22- Java的基类Object详解

    Java的基类Object详解 Java的JDK文档要经常查阅使用,最好查看英文的文档. Oracle官方在线 Java API Specifications http://www.oracle.co ...

最新文章

  1. 高频PCB设计事项一
  2. python的应用领域-Python的应用领域
  3. 矩阵乘法的四种理解方式
  4. Python语言学习:利用sorted对字典按照value进行递减排序,输出列表,并给定排名索引,组成新字典输出
  5. hdu 1573(中国剩余定理非互质情况)
  6. CentOS下的Mysql的安装和使用
  7. Windows平台下如何实现Unity3D下的RTMP推送
  8. idea junit 测试看不到控制台报错信息_高手都这么给 Spring MVC 做单元测试!
  9. android数据序列化的实现
  10. 针织erp_编程源于我们长期的针织工作
  11. 白帽SQL注入实战过程记录(2)——根据information_schema组装SQL注入语句
  12. 【整理】【原创】 什么是一维表,什么是二维表?----不同于 1维数组,2维数组
  13. 你对自己的定位是什么,就能成为什么样的人(转)
  14. hive中NULL值问题
  15. 全程无尿点,死磕前端~
  16. hadoop之mapreduce教程+案例学习(二)
  17. Luogu P4844 LJJ爱数数
  18. 计算机专业选i5八代还是i7八代,八代i5真的比七代i7更好?看看玩家的测试就知道!...
  19. html的ppt模板,[PPT模板]HTML_JS_CSS.ppt
  20. android系统更新桌面程序吗,为老人准备的安卓手机桌面程序:Big Launcher

热门文章

  1. py导入包异常跳出_马克的Python学习笔记#模块和包
  2. 经典html,经典 HTML
  3. linux 清空进程recv q,Linux中ss命令Recv-Q和Send-Q详解
  4. Python 做自动化测试环境搭建
  5. 聊聊 Jmeter 如何并发执行 Python 脚本
  6. 从手动测试菜鸟到自动化测试老司机,如何完成蜕变
  7. arcgis交通可达性分析步骤_【规划广角】街道慢行品质的多维度评价与导控策略——基于多源城市数据的整合分析...
  8. lisp 所在图幅号计算_图幅编号的计算
  9. python中for循环流程图_Javascript for循环_郭隆邦技术博客
  10. mysql自动备份工具 linux_自动备份MYSQL方法 (Linux)