Uživatelské nástroje

Nástroje pro tento web


vyuka:opakovani_-_metoda_addchild

Drag and Dropp

cepice_mc.addEventListener(MouseEvent.MOUSE_DOWN, chyt);
masleModra_mc.addEventListener(MouseEvent.MOUSE_DOWN, chyt);
masleCervena_mc.addEventListener(MouseEvent.MOUSE_DOWN, chyt);
bryle_mc.addEventListener(MouseEvent.MOUSE_DOWN, chyt);
	
function chyt(e:MouseEvent): void{
	e.target.startDrag();
	}
	
cepice_mc.addEventListener(MouseEvent.MOUSE_UP, Pust);
masleModra_mc.addEventListener(MouseEvent.MOUSE_UP, Pust);
masleCervena_mc.addEventListener(MouseEvent.MOUSE_UP, Pust);
bryle_mc.addEventListener(MouseEvent.MOUSE_UP, Pust);
	
function Pust(e:MouseEvent):void{
	e.target.stopDrag();
	}

Pro přehrání obsahu potřebujete Adobe Flash Plugin.

Drag and Dropp + addChild

Posunutí na horní vrstvu

karta1_mc.addEventListener(MouseEvent.MOUSE_DOWN, chyt);
karta2_mc.addEventListener(MouseEvent.MOUSE_DOWN, chyt);
karta3_mc.addEventListener(MouseEvent.MOUSE_DOWN, chyt);
karta4_mc.addEventListener(MouseEvent.MOUSE_DOWN, chyt);
	
function chyt(e:MouseEvent): void{
	e.currentTarget.startDrag();
	addChild(e.currentTarget as MovieClip);
	}
	
karta1_mc.addEventListener(MouseEvent.MOUSE_UP, Pust);
karta2_mc.addEventListener(MouseEvent.MOUSE_UP, Pust);
karta3_mc.addEventListener(MouseEvent.MOUSE_UP, Pust);
karta4_mc.addEventListener(MouseEvent.MOUSE_UP, Pust);
		
function Pust(e:MouseEvent):void{
	e.currentTarget.stopDrag();
	}

Pro přehrání obsahu potřebujete Adobe Flash Plugin.

Drag and Dropp + addChild

import flash.display.MovieClip;
import flash.geom.Point;

karta1_mc.addEventListener(MouseEvent.MOUSE_DOWN, chyt);
karta2_mc.addEventListener(MouseEvent.MOUSE_DOWN, chyt);
karta3_mc.addEventListener(MouseEvent.MOUSE_DOWN, chyt);
karta4_mc.addEventListener(MouseEvent.MOUSE_DOWN, chyt);
desk_mc.addEventListener(MouseEvent.MOUSE_DOWN, chyt);

function chyt(e:MouseEvent):void
{
	//trace(e.currentTarget.hitTestObject(desk_mc));
	//trace(desk_mc.hitTestObject(e.currentTarget as MovieClip));

	if (e.target.parent==desk_mc)
	{	
		desk_mc.addChild(e.target as MovieClip);

		var globalniSouradnice:Point = new Point();
		globalniSouradnice = desk_mc.localToGlobal(new Point(e.target.x,e.target.y));

		e.target.x = globalniSouradnice.x;
		e.target.y = globalniSouradnice.y;
	}
	e.target.startDrag();
	addChild(e.target as MovieClip);
}

karta1_mc.addEventListener(MouseEvent.MOUSE_UP, Pust);
karta2_mc.addEventListener(MouseEvent.MOUSE_UP, Pust);
karta3_mc.addEventListener(MouseEvent.MOUSE_UP, Pust);
karta4_mc.addEventListener(MouseEvent.MOUSE_UP, Pust);
desk_mc.addEventListener(MouseEvent.MOUSE_UP, Pust);

function Pust(e:MouseEvent):void
{
	e.target.stopDrag();
	if (e.target.hitTestObject(desk_mc) && e.target != desk_mc)
	{
		desk_mc.addChild(e.target as MovieClip);
		
		var lokalniSouradnice:Point = new Point();
		lokalniSouradnice = desk_mc.globalToLocal(new Point(e.target.x,e.target.y));
		
		e.target.x = lokalniSouradnice.x;
		e.target.y = lokalniSouradnice.y;
	}
}

Pro přehrání obsahu potřebujete Adobe Flash Plugin.

vyuka/opakovani_-_metoda_addchild.txt · Poslední úprava: 2011/09/15 16:30 autor: verca