• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 375
  • Last Modified:

Drag and drop

How do you create some dynamic actionscripting in a game for eg.
You have a few ball symbols on the stage and a symbol of a bag. You can only put 5 balls into the bag before you get a meassage that the bag is full. You move the balls into the bag using the startdrag and droptarget actions, the balls can also be removed by dragging them out of the bag again.

I know how to write this code its simple.
But how do you tell flash when the bag is full, and that no more balls can be put into the bag until a ball is dragged out. What will the code look like?????

Th closest example I could find was the "collision detection" example. But that only works if 2 objects collide not 5.

Please advise
 
0
yarmouth
Asked:
yarmouth
  • 13
  • 10
  • 3
  • +1
1 Solution
 
AlfaNoMoreCommented:
You will need a counter. Each drop will check the current value of this counter, and display message if counter = 5.

When a ball is dropped into the bag, add one more to the counter.

Quite simple really. No code, but you should be able to work it out. As you've done the rest of it!!!
0
 
AlfaNoMoreCommented:
Use this for a bit of help if you don't know actionScript.

I'm guessing that when the ball is moved over the bag, an action is called. Add this to that function.

Function DropBallsInBag
If iBallsInBag <= 5 Then
    iBallsInBag = iBallsInBag + 1
    '//Call RemoveBall function
Else
    '// Display your error message
End If
End Function
0
 
yarmouthAuthor Commented:
Looks promising, I will take a look and let you know.
And yes, I don't know much actionscripting.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
AlfaNoMoreCommented:
I don;t know actionScript either. That's VB, but I think Flash 4 actionScript was VB based. Flash 5 is javaScript based, but should be able to convert that for you.
0
 
shekarkrCommented:
Hi yarmouth,

You may find the following links useful(esp the first one). Check them out and let me know..

1. http://www.flashkit.com/tutorials/Interactivity/Other/Drag_n-Chris_Ma-192/index.shtml

2. http://www.flashkit.com/tutorials/Dynamic_Content/Create_a-Bob_Skid-212/index.shtml

Best Rgds,
Shekar
0
 
yarmouthAuthor Commented:
Below is my drag and drop code, where do I slot your code??
Basically I'm saying:
Drag 'app1' and droptarget 'chip1' and get a correct message.
Otherwise return to original x and y position and give an error message. Now where do I put your code???
PS:('app1' is the ball, 'chip1 is the bag')


on (press) {
    _root.icons.card1bigdup.chip1.app1.startDrag(true);
}
on (release) {
    stopDrag ();
    if (getProperty("/icons/card1bigdup/chip1/app1", _droptarget) eq "/icons/cardtop/chip2")
        tellTarget ("_root.icons.correct") {
            gotoAndPlay (2);
        }
    } else {
        setProperty ("_root.icons.card1bigdup.chip1.app1", _x, "15");
        setProperty ("_root.icons.card1bigdup.chip1.app1", _y, "-127");
        tellTarget ("_root.icons.error") {
            gotoAndPlay (2);
        }
    }
}
0
 
AlfaNoMoreCommented:
on (release) {
   if (balls_in_bag < 5) {
       stopDrag ();
       if (getProperty("/icons/card1bigdup/chip1/app1", _droptarget) eq "/icons/cardtop/chip2")
           tellTarget ("_root.icons.correct") {
               gotoAndPlay (2);
           }
       } else {
           setProperty ("_root.icons.card1bigdup.chip1.app1", _x, "15");
           setProperty ("_root.icons.card1bigdup.chip1.app1", _y, "-127");
           tellTarget ("_root.icons.error") {
               gotoAndPlay (2);
           }
       }
   else {
       gotoAndPlay (your error message);
   }
}

That should do it. Make sure you declare/ create a variable balls_in_bag = 0 at the beginning of your movie, but don't loop back to this frame, else your current count will be nulled!!!
0
 
AlfaNoMoreCommented:
if (getProperty("/icons/card1bigdup/chip1/app1", _droptarget) eq "/icons/cardtop/chip2")
          tellTarget ("_root.icons.correct") {
              balls_in_bag += 1;
              gotoAndPlay (2);
          }
0
 
yarmouthAuthor Commented:
Just one thing.

on (release) {
  if (balls_in_bag < 5) {
      stopDrag ();

Where does the "balls_in_bag" come from?
Is it an instance name, mc name, how does flash know that I'm referencing my balls_in_the_bag?????

0
 
AlfaNoMoreCommented:
It's a variable. One of the actionScript commands is "set variable". Just use this on your very first frame. Set it to equal 0 (as an integer, not string. No quotes around it in the little box).
0
 
yarmouthAuthor Commented:
Your quote: "That should do it. Make sure you declare/ create a variable balls_in_bag = 0 at the beginning of your
movie, but don't loop back to this frame, else your current count will be nulled!!!"

Ok, I have done this. Does it matter if my mc IS only 1 frame long?
0
 
yarmouthAuthor Commented:
AlfaVoMore,

on (press) {
     _root.icons.card1bigdup.chip1.app1.startDrag(true);

on (release) {
  if (balls_in_bag < 5){
      stopDrag ();
      if (getProperty("/icons/card1bigdup/chip1/app1", _droptarget) eq "/icons/cardtop/chip2")
         tellTarget ("_root.icons.correct") {
             balls_in_bag += 1;
             gotoAndPlay (2);
         }          
      } else {
          setProperty ("_root.icons.card1bigdup.chip1.app1", _x, "15");
          setProperty ("_root.icons.card1bigdup.chip1.app1", _y, "-127");
          tellTarget ("_root.icons.error") {
              gotoAndPlay (2);
          }
      }
  else {
      gotoAndPlay ("_root.icons.error");
  }
}

OK this is what I have so far, don't know what's wrong because it won't let me back into normal mode as this code contains errors!
Where are they? What am I doning wrong? Please advise
0
 
yarmouthAuthor Commented:
AlfaNoMore!

Please help me!!!!!
0
 
AlfaNoMoreCommented:
0
 
AlfaNoMoreCommented:
Sorry, I was away at lunch!! Maybe it's this: balls_in_bag += 1; That's standard javascript. Try

balls_in_bag = balls_in_bag + 1;
0
 
AlfaNoMoreCommented:
This might cause probs also:

if (getProperty("/icons/card1bigdup/chip1/app1", _droptarget) eq "/icons/cardtop/chip2")
        tellTarget ("_root.icons.correct") {
            balls_in_bag += 1;
            gotoAndPlay (2);
        }          
     

Change to:

if (getProperty("/icons/card1bigdup/chip1/app1", _droptarget) eq "/icons/cardtop/chip2") {
    tellTarget ("_root.icons.correct") {
        gotoAndPlay (2);
    }          
    /:balls_in_bag = /:balls_in_bag + 1;
}

/:balls_in_bag means reference the variable balls_in_bag inside the root movie.
0
 
yarmouthAuthor Commented:
Just excuse me if I sound thick. But, where does this bit go??

on (press) {
    _root.icons.card1bigdup.chip1.app1.startDrag(true);

on (release) {
 if (balls_in_bag < 5){
     stopDrag ();
     if (getProperty("/icons/card1bigdup/chip1/app1", _droptarget) eq "/icons/cardtop/chip2")
        tellTarget ("_root.icons.correct") {
                   gotoAndPlay (2);
   }          
   _root.icons.cardtop.chip2.balls_in_bag = _root.cardtop.chip2.balls_in_bag + 1;
}

        }          
     } else {
         setProperty ("_root.icons.card1bigdup.chip1.app1", _x, "15");
         setProperty ("_root.icons.card1bigdup.chip1.app1", _y, "-127");
         tellTarget ("_root.icons.error") {
             gotoAndPlay (2);
         }
     }
 else {
     gotoAndPlay ("_root.icons.error");
 }
}

This is what I have, but is it correct?
I have included the set variable balls_in_bag to 0 in the first frame. You spoke of a:
Function DropBallsInBag earlier up, what is this, have I left it out? Sorry for sounding ignorant, but I'm  a designer and know very little about coding in ANY language.
0
 
AlfaNoMoreCommented:
You could send me the Flash file if you want!!!?

daniel.newman@bis-web.com
0
 
AlfaNoMoreCommented:
I've never seen coding like yours before. Is Flash 5 writing that for you?

I would have "/icons/card1bigdup/chip1/app1" instead of your "_root.icons.card1bigdup.chip1.app1"
0
 
yarmouthAuthor Commented:
Trust me you won't have the time or patience to wade throu my file, it's huge and consists of about 100 different movie clips, all on different levels calling all sorts of things. Couldn't ask that of you.....

Ok just answer one question for the 100 points.
How do you create a counter.
Or maybe you know a tutorial?
0
 
yarmouthAuthor Commented:
Nope that's my dodgey code. But it's just flash 5 syntax. The / way is flash 4
0
 
AlfaNoMoreCommented:
that's what the balls_in_bag is.

in this current movie, create the variable "balls_in_bag" and make it 0.

I see you've tried to reference an object called balls_in_bag, which probably isn't the way to do it. I don't know Flash 5 (oops), but I can probably figure most of it out.


Add this code.

on (release) {
trace(balls_in_bag); should display a little alert window.
whenever you refer to this local variable, just do it by it's name. No root references.

Take out the first if (balls_in_bag < 5) as we're not sure this is working.

But change
  _root.icons.cardtop.chip2.balls_in_bag = _root.cardtop.chip2.balls_in_bag + 1;
to
  balls_in_bag = balls_in_bag + 1;

Don't know what else to suggest. In Flash 4, whenever you referenced a variable inside a different movie, you had to add the : before its name, so if your balls_in_bag is created in another movie, then reference it using this syntax

_root.movie1:balls_in_bag

I think this is right!
0
 
AlfaNoMoreCommented:
and all that on(press/release) code goes on the button. inside your ball movie, double click on the button, and view it's actions. Stick it in there.
0
 
shekarkrCommented:
Boy oh boy, is this going on and on :)!!!

BTW, yarmouth, did you check out the link or no??

Shekar.
0
 
shekarkrCommented:
He's given how to declare the variable, how to enter the stuff into the windo wand all that, with screenshots. This will help you a long way in putting in all the code that you are talking about.

Shekar.
0
 
rootdirCommented:
Am I on long drive(Laborday weekend)?

I enjoyed this question thanks you both yarmouth, AlfaNoMore.

Cheers
RootDir
0
 
yarmouthAuthor Commented:
Thanks for all your help AlfaNoMore!
Didn't quite get all you did, but I'm sure the answer's in there somewhere......
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 13
  • 10
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now