Copy link to clipboard
Copied
Dear masters,
I beg enlightenment, I was made toys. where if the "process button" I click he will draw according to the size of the input that I entered. now the problem is how can I create a new image and can be dragged drop but without deleting the old image and the new image does not in front of the old image. so as if we make more than one picture and each can be dragged drop, but from one button "process"?
what happened today, I can made picture a lot but when in drag drop, all the pictures move together. I want only picture which I Click can move, but another not.
here my code :
import flash.display.MovieClip; import flash.events.MouseEvent; import flash.events.Event; var mc:MovieClip = new MovieClip(); mc.buttonMode = true; var randomColours:int = Math.floor(Math.random() * 0xFFFFFF); process_btn.addEventListener(MouseEvent.CLICK, process); mc.addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown); mc.addEventListener(MouseEvent.MOUSE_UP, item_onMouseUp); function item_onMouseDown(event:MouseEvent):void { mc.startDrag(); } function item_onMouseUp(event:MouseEvent):void { mc.stopDrag(); } function process(event:MouseEvent):void { panjang = Number(panjang_txt.text); lebar = Number(lebar_txt.text); mc.graphics.lineStyle(4, 0x000000, .5); mc.graphics.beginFill(randomColours, .2); mc.graphics.drawRect(0, 0,(panjang/10)/1.3, lebar/10); mc.graphics.endFill(); mc.x = 20; mc.y = 150; addChild(mc); } |
regards,
Prabowo
Copy link to clipboard
Copied
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
var randomColours:int = Math.floor(Math.random() * 0xFFFFFF);
process_btn.addEventListener(MouseEvent.CLICK, process);
mc.addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
mc.addEventListener(MouseEvent.MOUSE_UP, item_onMouseUp);
function item_onMouseDown(event:MouseEvent):void {
mc.startDrag();
}
function item_onMouseUp(event:MouseEvent):void {
mc.stopDrag();
}
function process(event:MouseEvent):void
{
panjang = Number(panjang_txt.text);
lebar = Number(lebar_txt.text);
//move the instantiation inside the function
var mc:MovieClip = new MovieClip();
mc.buttonMode = true;
mc.graphics.lineStyle(4, 0x000000, .5);
//if you want to have different random colors move the var also here
var randomColours:int = Math.floor(Math.random() * 0xFFFFFF);
mc.graphics.beginFill(randomColours, .2);
mc.graphics.drawRect(0, 0,(panjang/10)/1.3, lebar/10);
mc.graphics.endFill();
mc.x = 20;
mc.y = 150;
addChild(mc);
//and the eventlistners
mc.addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
mc.addEventListener(MouseEvent.MOUSE_UP, item_onMouseUp);
}
and change this:
function item_onMouseDown(event:MouseEvent):void {
event.currentTarget.startDrag();
}
function item_onMouseUp(event:MouseEvent):void {
event.currentTarget.stopDrag();
}
this should do the trick
Copy link to clipboard
Copied
thank you mocca, the problem has solved.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now