02-12-2006, 14:02
|
|
|
חבר מתאריך: 09.12.05
הודעות: 205
|
|
משהו שעשיתי
בניתי משהו בשביל להתאמן. אני שמח לקבל חוות דעת בונות (בבקשה בלי שטויות) ועצות על איך לשפר את הקוד.
https://2006-uploaded.fresh.co.il/2...02/93742882.swf
the code that is in the ball:
קוד:
onClipEvent (load) {
i = 0;
}
on (press)
{
_root.attachMovie("ball","ball"+i,1000+i,{_x:this._x,_y:this._y});
startDrag(_root["ball"+i],true);
_root.actions(_root["ball"+i]);
_root.objects[_root.i] = ["ball"+i];
_root.i++;
i++;
}
on (releaseOutside)
{
stopDrag();
}
*the code in the cube is the same just replace the word ball with cube
the code in the frame:
קוד:
objects = new Array();
i = 0;
function actions(object)
{
object.xdir=1;
object.ydir=1;
object.onEnterFrame = function()
{
this._x+=10*this.xdir;
this._y+=10*this.ydir;
if (this._x>550-this._width/2)
{
this.xdir*=-1;
this._x=550-this._width/2
}
if (this._x<0+this._width/2)
{
this.xdir*=-1;
this._x=0+this._width/2
}
if (this._y>400-this._height/2)
{
this.ydir*=-1;
this._y=400-this._height/2
}
if (this._y<0+this._height/2)
{
this.ydir*=-1;
this._y=0+this._height/2
}
for (i=0;i<_root.objects.length;i++)
{
if (this.hitTest(_root[objects[i]]) && _root[objects[i]]!=_level0[this._name])
{
this._x-=10*this.xdir/2;
this._y-=10*this.ydir/2;
this.xdir*=-1;
this.ydir*=-1;
}
}
}
object.onPress = function()
{
startDrag(this,true);
}
object.onRelease = function()
{
stopDrag();
}
}
הקוד הוא די פשוט (למי שמבין קצת) ואני לא חושב שיש פה הרבה מה להסביר. רק למי שלא הבין המערך OBJECTS מכיל את כל ה- MC על ה- FRAME חוץ מהעיגול והריבוע המקוריים ולפיו אני בודק פגיעות (HITTEST).
|