Solved

Drag and drop

Posted on 2001-08-31
27
362 Views
Last Modified: 2012-06-27
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
Comment
Question by:yarmouth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 10
  • 3
  • +1
27 Comments
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6444371
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
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6444380
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
 

Author Comment

by:yarmouth
ID: 6444422
Looks promising, I will take a look and let you know.
And yes, I don't know much actionscripting.
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6444442
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
 
LVL 3

Expert Comment

by:shekarkr
ID: 6444454
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
 

Author Comment

by:yarmouth
ID: 6444458
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
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6444535
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
 
LVL 9

Expert Comment

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

Author Comment

by:yarmouth
ID: 6444587
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
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6444638
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
 

Author Comment

by:yarmouth
ID: 6444668
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
 

Author Comment

by:yarmouth
ID: 6444701
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
 

Author Comment

by:yarmouth
ID: 6444785
AlfaNoMore!

Please help me!!!!!
0
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6444916
0
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6444933
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
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6444953
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
 

Author Comment

by:yarmouth
ID: 6445011
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
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6445084
You could send me the Flash file if you want!!!?

daniel.newman@bis-web.com
0
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6445099
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
 

Author Comment

by:yarmouth
ID: 6445111
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
 

Author Comment

by:yarmouth
ID: 6445120
Nope that's my dodgey code. But it's just flash 5 syntax. The / way is flash 4
0
 
LVL 9

Accepted Solution

by:
AlfaNoMore earned 100 total points
ID: 6445168
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
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6445180
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
 
LVL 3

Expert Comment

by:shekarkr
ID: 6446054
Boy oh boy, is this going on and on :)!!!

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

Shekar.
0
 
LVL 3

Expert Comment

by:shekarkr
ID: 6446076
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
 
LVL 6

Expert Comment

by:rootdir
ID: 6446842
Am I on long drive(Laborday weekend)?

I enjoyed this question thanks you both yarmouth, AlfaNoMore.

Cheers
RootDir
0
 

Author Comment

by:yarmouth
ID: 6449947
Thanks for all your help AlfaNoMore!
Didn't quite get all you did, but I'm sure the answer's in there somewhere......
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
YouTube Link 10 372
Action Script commands 3 224
Action Script commands 4 331
Adobe Acrobat Pro: chasing the white background wallpaper dimensions 3 239
I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question