Adobe Flash Anleitung | MovieClips mit Geraden verbinden

S

sevY

Hi zusammen,

a short one…

Wenn ihr MovieClips mit Geraden verbinden wollt, geht das ganz einfach mit folgendem Script:

PHP:
//Actionscript 1.0
MovieClip.prototype.draw=function(x,y,lineSize,colour,alpha)
     {
    this.lineStyle (lineSize, colour, alpha);
    with(this)
        {
        lineTo(x, y);
        }
    };
_root.mc1.draw(_root.mc2._x-_root.mc1._x,_root.mc2._y-_root.mc1._y,2,'0xff0000',60);
_root.mc2.draw(_root.mc3._x-_root.mc2._x,_root.mc3._y-_root.mc2._y,2,'0xff0000',60);


Damit kann man dann hinterher noch nette Animationen basteln… zb. die MovieClips anfassen und durch die Gegend ziehen… sieht verrückt aus…

PHP:
//Actionscript 1.0
MovieClip.prototype.draw=function(x,y,lineSize,colour,alpha)
     {
    this.lineStyle (lineSize, colour, alpha);
    with(this)
        {
        lineTo(x, y);
        }
    };
this.onEnterFrame=function()
    {
    _root.mc1.draw(_root.mc2._x-_root.mc1._x,_root.mc2._y-_root.mc1._y,2,'0xff0000',60);
    _root.mc2.draw(_root.mc3._x-_root.mc2._x,_root.mc3._y-_root.mc2._y,2,'0xff0000',60);
    }

_root.mc1.onPress=function()
    {
    this.startDrag();
    }
_root.mc2.onPress=function()
    {
    this.startDrag();
    }
_root.mc3.onPress=function()
    {
    this.startDrag();
    }
  
_root.mc1.onRelease=function()
    {
    this.stopDrag();
    }
_root.mc2.onRelease=function()
    {
    this.stopDrag();
    }
_root.mc3.onRelease=function()
    {
    this.stopDrag();
    }

Oder noch schlimmer… einfach alles zufällig durch die Gegend wirbeln lassen bis irgendwann die Performance im Keller ist, da alles vollgekritzelt wurde…

PHP:
MovieClip.prototype.draw=function(x,y,lineSize,colour,alpha)
     {
    this.lineStyle (lineSize, colour, alpha);
    with(this)
        {
        lineTo(x, y);
        }
    };
this.onEnterFrame=function()
    {
    _root.mc1.draw(_root.mc2._x-_root.mc1._x,_root.mc2._y-_root.mc1._y,2,'0xff0000',60);
    _root.mc2.draw(_root.mc3._x-_root.mc2._x,_root.mc3._y-_root.mc2._y,2,'0xff0000',60);
    _root.mc1._x=random(400);
    _root.mc1._y=random(200);
    _root.mc2._x=random(400);
    _root.mc2._y=random(200);
    _root.mc3._x=random(400);
    _root.mc3._y=random(200);
    }



Liebe Grüße

Yves
 
Hier noch ein Beispiel dazu… diesmal mit clear(), damit die Linien sich nicht überlagern.
Die Kugeln 1 , 2 , 3 sind mit den Tasten 1 , 2 , 3 ansprechbar. Falls eine dieser Tasten gedrückt ist, oder eine Kombination dieser, kann man mittels der Pfeiltasten die Zeichnung steuern.

PHP:
//Actionscript 1.0
MovieClip.prototype.draw = function(x, y, dicke, farbe, alpha)
     {
    this.clear();
    this.lineStyle(dicke, farbe, alpha);
    this.moveTo(0, 0);
    this.lineTo(x, y);
    };
punkt2.onEnterFrame = function()
    {
    _root.punkt1.draw(_root.punkt2._x-_root.punkt1._x, _root.punkt2._y-_root.punkt1._y, 2, '0x000000', 100);
    _root.punkt2.draw(_root.punkt3._x-_root.punkt2._x, _root.punkt3._y-_root.punkt2._y, 2, '0x000000', 100);
    _root.punkt3.draw(_root.punkt1._x-_root.punkt3._x, _root.punkt1._y-_root.punkt3._y, 2, '0x000000', 100);
   
    if (Key.isDown(Key.DOWN))
        {
        if(Key.isDown(49))
            {              
            _root.punkt1._y += 1;
            }
        if(Key.isDown(50))
            {
            _root.punkt2._y += 1;
            }
        if(Key.isDown(51))
            {
            _root.punkt3._y += 1;
            }
        }
      
    if (Key.isDown(Key.UP))
        {
        if(Key.isDown(49))
            {              
            _root.punkt1._y -= 1;
            }
        if(Key.isDown(50))
            {
            _root.punkt2._y -= 1;
            }
        if(Key.isDown(51))
            {
            _root.punkt3._y -= 1;
            }
        }
    if (Key.isDown(Key.LEFT))
        {
        if(Key.isDown(49))
            {              
            _root.punkt1._x -= 1;
            }
        if(Key.isDown(50))
            {
            _root.punkt2._x -= 1;
            }
        if(Key.isDown(51))
            {
            _root.punkt3._x -= 1;
            }
        }
    if (Key.isDown(Key.RIGHT))
        {
        if(Key.isDown(49))
            {              
            _root.punkt1._x += 1;
            }
        if(Key.isDown(50))
            {
            _root.punkt2._x += 1;
            }
        if(Key.isDown(51))
            {
            _root.punkt3._x += 1;
            }
        }
};

Liebe Grüße

Yves
 
Zurück
Oben Unten