Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to drag/drop image from other image in one container

New Here ,
May 22, 2013 May 22, 2013

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

TOPICS
ActionScript
370
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
May 22, 2013 May 22, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 22, 2013 May 22, 2013
LATEST

thank you mocca, the problem has solved.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines