嵌套组件相互使用
未识别博客 · mojaves · 2004-12-20(近似)
/
首页
/
嵌套组件相互使用
peter hall 提供的一种嵌套组件相互使用的方法:
对于相互嵌套的组件,如果你想通过容器构造器(he container's constructor)使用这些组件的方法,
你不得不使用attachMovie以保证这些嵌套的组件的class被指派和它的构造器被执行(原因是组件未
被初始化)。当你布置这些组件的时候,很麻烦,因为你不得不自己动手编写程序。下面提供的方法,
可以允许你强制组件初始化,这样你就可以灵活的放置它们。
这个方法的原理是来源于在父组件被初始化之前,组件的参数已经被指派到组件。你唯一需要知道的
就是这个组件的linkID,或者修改组件的参数使它包含一个叫linkID的参数。请在某个地方放置这个方法:
MovieClip.prototype.initializeComponent = function(linkID){
// get the standard MovieClip properties
with(this){
var initObj = {_x: _x, _y: _y,
_xscale: _xscale, _yscale: _yscale,
_rotation: _rotation,
_alpha: _alpha, _visible: _visible
};
}
// collect all the component parameters
for(var i in this){
initObj
= this
;
}
if(linkID == undefined) linkID = this.linkID;
if(linkID == undefined){
// initialisation failed
return false;
}else{
// re-attach the symbol, exactly as before.
this._parent.attachMovie(linkID, this._name, this.getDepth(), initObj);
// initialisation succeeded
return true;
}
}
下面是应用它的一个实例:
function MyComponentClass(){
this.init();
}
MyComponentClass.prototype = new MovieClip();
Object.registerClass("MyComponentSymbol",MyComponentClass);
MyComponentClass.prototype.init = function(){
// initialise the scrollbar
this.scrollBar_mc.initializeComponent("FScrollbarSymbol"
;
// now do stuff with the scrollbar
this.scrollBar_mc.setScrollPosition(30);
}
是的,你可以看出来,使用它,把它作为一个你希望初始化的组件的一个方法来引用就可以了。
mojaves
at
|
Trackback(
0
)
so help me to get where i belong......i love u Y tou....forever.hehehaha………………
评论
想说的啥?
最后更新
春天来时 When.Spring.Comes
试听:许巍新专辑第一推荐曲《曾经的你》
3日晚,看了部电影
HAPPY TOGETHER
青春后遗症
FREE THE DEPT.
Thank You for Hearing Me
KFC vs 回锅肉
回来了
棉花
原始快照:web.archive.org