View Full Version : Is it possible to store complex functions and event handlers inside #initclip block?
divarch
02-09-2004, 06:10 AM
Hi guys,
today I began my work on my 3rd component, :) and this is how things are put....
It would be a 'window-type' component, similar to 'toolbar panels' inside Flash environment.
So, for start, it will have a title bar and a main window, with close and resize buttons.
Now, for example, resizing is done like:
function stretch(clip) {
if (stretching) {
clip.onEnterFrame = function() {
difX = _root._xmouse-clip._x;//button is lower right, and clip's registration is upper-left
difY = _root._ymouse-clip._y;
setProperty(clip, _width, difX);
setProperty(clip, _height, difY);
};
} else {
delete clip.onEnterFrame;
}
}
and that is invoked like this:
this.bgnd_mc.stretch_btn.onPress=function(){
stretching=true;
stretch(this._parent._parent);//I always put the code on one timeline
};
This all works, but how can I put it in a component package?
I know all methods should be defined as Class prototypes, and even then, my buttons won't work...
Do I have to include 'onPress' handlers inside the 'stretching' function and then just initialize it within class constructor??
Please help...
I am sorry for such a long and boring post, but imagine I have to copy all the code when making another instance of "myWindow" class...
Thanks
hangalot
02-10-2004, 02:08 AM
what the #initclip and #endinitclip do is compile a class and execute the Object.registerclass before the first instance is placed on the stage. thus if u have class wich u place in an mc and u put that mc on the stage by placing that code inside the ## 's it will execute b4 the first frame.
i have pasted an example of a class outline, notice the object.registerclass - readup about that if u r uncertain.
#initclip
//8:58 AM 2/10/2004
myClass = function(){
super();
}
myClass.prototype = new MovieClip();
Object.registerClass("movie_myClass",myClass);
myClass.prototype.someArbProperty = "some arb value";
myClass.prototype.some_arb_method = function(){
return;
}
#endinitclip
divarch
02-10-2004, 03:22 PM
Yes, thanks for the reply, I am familiar with class structure, and assigning methods inside it. But my question was somewhat different.
See in your example, you have a prototype method, 'some arb_method', and that's OK, I have 'move' method, but....
I was asking about another type of functions.
I may have two buttons inside a component, and they have different methods, and they all involve main, parent mc.
So is this legal, or is there another way, cause I know this works:
//Class constructor
function Window(){
//...set x, y , width, etc.... then
this.button1=this.myBtn1;
this.button2=this.myBtn2;//myBtn2 is instance name
//invoke methods
this.move(this);
}
//methods
Window.prototype.move=function(clip){
this.button1.onRelease=function(){
clip.onEnterFrame=function(){
clip._x+=50;//for example
}
}
//This is only a shortened example
Now, I have skipped some parts in typing, but I hope you get the idea.
Back to my original question:
Can I define methods, which will be usable only within it's class, with it's invokers(buttons) as class's properties(this.button1=this.myBtn1;)???
Thanks
hangalot
02-11-2004, 01:49 AM
ah, i think i understand now. u want to access a button inside the component.
if the button is a movie clip then i tend to just declare the instance name as a var in the class scope. then use that.
thus if i have a button component called btn1 then in the class i declare it as follows
class bla extends MovieClip{
private btn1;
function someArbFunc(){
btn1.onRelease = {};
}
}
i hope i understood u better now.
divarch
02-11-2004, 02:00 AM
Yes, you do understand me better now, sorry for me being not descriptive enough.
I do have several mc's in my component, but they are not components themselves, just plain mc's, and their methods all affect _parent component, like 'stretch' method on a 'stretch_btn' affecting the whole component.
Just as all the functions are somewhat complex, I am puzzled how to create them properly, but then again, that only depends on the certain problem.:rolleyes:
I will paste one now, sorry for the length:
Windows.prototype.stretch = function(clip) {
this.stretch_btn.onPress = function() {//building in 'onPress' handler
this.useHandCursor = false;
stretching = !stretching;
clip.onEnterFrame = function() {//referring to main component
if (stretching) {
difX = _root._xmouse-clip._x;
difY = _root._ymouse-clip._y;
setProperty(clip, _width, difX);
setProperty(clip, _height, difY);
if (clip._width<180 || clip._height<80) {
setProperty(clip, _width, 200);
setProperty(clip, _height, 200/1.5);
delete clip.onEnterFrame;
}
if (clip._width>620 || clip._height>420) {
setProperty(clip, _width, 600);
setProperty(clip, _height, 600/1.5);
delete clip.onEnterFrame;
}
} else {
delete clip.onEnterFrame;
}
};
};
this.stretch_btn.onReleaseOutside = function() {
stretching = !stretching;
delete clip.onEnterFrame;
};
this.stretch_btn.onRelease = this.stretch_btn.onReleaseOutside;
this.stretch_btn.onRollOver = function() {
this.gotoAndStop(2);
this.useHandCursor = true;
};
};
Just to call it like this in the class constructor:
//stretcher
this.stretch(this);
Stupid, ha?
Thanks for your efforts
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.