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

Draggable object back to original position when already there is an object at the drop area.

Explorer ,
Feb 07, 2017 Feb 07, 2017

Copy link to clipboard

Copied

I'm a newbie about flash, especially actionscript.

So the scenario is: I have 3 pairs of shoes, 2 ties, and 4 scouts.

I already made the 3 pairs of shoes and 2 ties draggable to any scouts (as the drop area).

But the problem is, I want to make it clear, that the user only may put a pair of shoes and a tie on 1 scout.

Because what I have now is, when already exist a pair of shoes and a tie on a scout, the user still can drop other on it.

Please help me, I've been surfing through internet and many forums but still can't solve this one. Many thanks before.

[Animate replaced Flash Pro]

[Moved from non-technical Forum Lounge to specific Program forum... Mod]

[Here is the list of all Adobe forums... https://forums.adobe.com/welcome]

Views

955

Translate

Translate

Report

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

correct answers 1 Correct answer

LEGEND , Feb 07, 2017 Feb 07, 2017

Oh dear lord, let's clean that up...

// this code is on tie1

on (press) {

    if (!this.isLocked) {

        startDrag(this);

    }

}

on (release) {

    stopDrag();

    // anak1 is scout1

    if (this._droptarget == "/anak1") {

        this._x = 163.95;

        this._y = 401.45;

        var isLocked = true;

        var efeksound:Sound = new Sound();

        efeksound.attachSound("plopp");

        efeksound.start();

    }

    else if (this._droptarget == "/anak2") {

        this._x = 293.95;

        this._y = 401.45;

...

Votes

Translate

Translate
LEGEND ,
Feb 07, 2017 Feb 07, 2017

Copy link to clipboard

Copied

Should be trivial. Just set a variable on the dropped-on object to true when something is dropped on it. Then have your drop code check for that variable. If it's set, put it back.

Votes

Translate

Translate

Report

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
Explorer ,
Feb 07, 2017 Feb 07, 2017

Copy link to clipboard

Copied

alright, thanks, i get the logic from your idea, but i don't know what variable i should use

Votes

Translate

Translate

Report

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
LEGEND ,
Feb 07, 2017 Feb 07, 2017

Copy link to clipboard

Copied

.idontknowwhatvariableishoulduse = true;

It literally doesn't matter. It's a variable name. You just make up whatever makes sense to you.

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 07, 2017 Feb 07, 2017

Copy link to clipboard

Copied

one way to do this:

each scout (assuming that's a movieclip) could have its own clothes object (eg, clothesObj) with a shoes property and a tie property.  if that property already exits return it to its start point and replace that clothesObj property with the just dropped one.

eg, initialize your objects:

for(var i:int=0;i<4;i++){

this['scout'+i].clothesObj={};

}

and in your drop function, if you drop shoes1 on scout3:

if(scout3.clothesObj.shoes){

scout3.clothesObj.shoes.x=scout3.clothesObj.shoes.initX;  // assuming you assigned initX and initY for your draggables

scout3.clothesObj.shoes.y=scout3.clothesObj.shoes.initY;

}

scout3.clothesObj.shoes=shoes1;

Votes

Translate

Translate

Report

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
Explorer ,
Feb 07, 2017 Feb 07, 2017

Copy link to clipboard

Copied

thanks for your help

but i see this code is about to place/snap the draggable object to the shoes position, isn;t it?

if yes, i already done with this, but still confuse about detect if an object is already exist on the drop zone or not.

if(scout3.clothesObj.shoes){

scout3.clothesObj.shoes.x=scout3.clothesObj.shoes.initX;  // assuming you assigned initX and initY for your draggables

scout3.clothesObj.shoes.y=scout3.clothesObj.shoes.initY;

}

scout3.clothesObj.shoes=shoes1;

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 07, 2017 Feb 07, 2017

Copy link to clipboard

Copied

copy and paste here your drop function code.

Votes

Translate

Translate

Report

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
Explorer ,
Feb 07, 2017 Feb 07, 2017

Copy link to clipboard

Copied

this so far the code i have //this code is on tie1 on(press) { if (!this.isLocked) startDrag(this); } on(release){stopDrag(); if(this._droptarget=="/anak1")//anak1 is scout1 { this._x=163,95; this._y=401,45; var isLocked = true; var efeksound:Sound = new Sound(); efeksound.attachSound("plopp"); efeksound.start(); } else if(this._droptarget=="/anak2") { this._x=293,95; this._y=401,45; } else{ this._x=867,50; this._y=408,95; } }

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 07, 2017 Feb 07, 2017

Copy link to clipboard

Copied

that's actionscript 2.  actually, i think that's as1 and predates even my wizend macromedia flash coding history.

anyway, you can't possibly be using animate cc for that.

post in the as1/as2 forum, ActionScript 1 and 2

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 07, 2017 Feb 07, 2017

Copy link to clipboard

Copied

thinking about it further, i suggest you learn as3.

as far as i can tell, i'm the only person that even responds to as1/as2 posts and i'm not sure i'll respond to your message because it demonstrates the worst of as1/as2 coding (and there's a lot to not like about as1/as2).

don't take any of that criticism personally: you didn't invent as1/as2.  but perpetuating it when there's a much better option is unwise.

Votes

Translate

Translate

Report

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
Explorer ,
Feb 09, 2017 Feb 09, 2017

Copy link to clipboard

Copied

LATEST

Thanks for directing me to this as2 link, I thought I was in the right forum.

And yeah thanks for your advice, but I just continue my animator works and he used as2 so I need to stick to it till the end

ClayUUID​ thanks for re-write the code! that's my code really looks like hehe, I don't know how to write like that in comment section (I'll figure out next time I post). But again, that code really works on my file.

Votes

Translate

Translate

Report

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
LEGEND ,
Feb 07, 2017 Feb 07, 2017

Copy link to clipboard

Copied

Oh dear lord, let's clean that up...

// this code is on tie1

on (press) {

    if (!this.isLocked) {

        startDrag(this);

    }

}

on (release) {

    stopDrag();

    // anak1 is scout1

    if (this._droptarget == "/anak1") {

        this._x = 163.95;

        this._y = 401.45;

        var isLocked = true;

        var efeksound:Sound = new Sound();

        efeksound.attachSound("plopp");

        efeksound.start();

    }

    else if (this._droptarget == "/anak2") {

        this._x = 293.95;

        this._y = 401.45;

    }

    else {

        this._x = 867.50;

        this._y = 408.95;

    }

}

First problem I see is var isLocked = true;. That should be this.isLocked = true;.

Votes

Translate

Translate

Report

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