My Flash Resource - New Ideas and News for Applying Flash to Complex Gaming Apps

Latest News and Developments

April 17, 2008

Drag and Drop Initiates Action Effect

by @ 2:34 pm. Filed under Flash Tutorials

In this Flash tutorial you will first create a symbol (object) that you can drag and drop around the screen. Next you will create a drop zone area that will cause the symbol (object) to react when it is dropped into the target area by performing a hit test. As always the completed source file is included.

Download the source file: drag_n_drop.fla

This Flash tutorial will be presented in a step-by-step format. Even though the source file and the example includes two different drop areas, I will only be teaching how to make one of them.

You should be able to figure out how to make more are completing this Flash tutorial.

Set up the Timeline

1. Open Flash, create a new Flash Document and create three layers labelled (from top to bottom): Actions, drag_me symbol, landing area.

Creating a drag - able symbol in Flash:

2. On the first frame of the ‘drag_me symbol’ layer, draw whatever it is that you want to be you drag and drop object, I used my cartoon head. Use the selection tool to select your entire drawing and turn it into a movieclip symbol. You can do this by clicking Modify>Convert to symbol (or using the shortcut key: F8).
3. Name your movieclip (the instance name) ‘drag_me’. The instance name is located in the properties panel.

Flash Tutorial Image

4. We have to edit the movieclip, so double-click on the movieclip and you will be in editing mode. Notice the little crosshairs in the top-left corner of your graphic, we want these to be in the exact middle of your graphic. So select your graphic and move it until the crosshairs is in the middle. This is important for when we perform the hit test later. When your done, go back to the main timeline by double-clicking outside of you graphic.

5. On the first frame of the ‘Actions’ layer. Add the following actions, which will allow your movieclip to be drag and drop (ed):

// drag while mouse is pressed.
drag_me.onPress = function() {

startDrag(this, false);

}

// stop dragging when mouse button is released.
drag_me.onRelease = function() {

stopDrag();

}

// stop dragging when mouse is released outside,
// just to make sure the object gets released.
drag_me.onReleaseOutside = function() {

stopDrag();

}

Test your movie and see if it works.

Create the landing area

6. On the first frame of the ‘landing area’ layer, draw a landing area. I used a circle and a square. After you have drawn the landing area convert it into a movieclip the same way you did in step 2. Name your movieclip circleHit (instance name) or whatever you want, but I have used circleHit in my source file. You also have to edit this movieclip to make the crosshairs appear in the center on the symbol like you did in step 4.

7. Now for the tricky part. You have to create a hit test so that you can perform an action when the ‘drag_me’ clip is dragged into the landing area. The reason you centered the two movieclips you made is so that when we get their x and y position we will be refering to the center of the movieclip symbol rather than the top left. The following actionscript will define the target area that we will trigger the actions:

// calculate circle hit area
C_hitLeft_x = circleHit._x - 6;
C_hitTop_y = circleHit._y + 6;
C_hitRight_x = circleHit._x + 6;
C_hitBottom_y = circleHit._y - 6;

8. Next we define the conditions for a hit using an if…then statement in the drag_me.onRelease function:

drag_me.onRelease = function() {

stopDrag();
// if drag_me is in the circle hit area then make it black
if (this._x < C_hitRight_x && this._x > C_hitLeft_x && this._y < C_hitTop_y && this._y > C_hitBottom_y) {

this.gotoAndStop(5); // perform some action.

}
else {

this.gotoAndStop(1); // else do nothing

}

In my source file I have made my ‘drag_me’ movieclip a little more diverse. I basically just change its qualities throughout the timeline so that on Frame 5, I put a stop() action and made the symbol completely black. That is why my action is this.gotoAndStop(5). I decided to leave this out of the tutorial because ideally you can perform any action you want at this step, I’ll leave that up to you. Following is the complete actionscript for this tutorial, all of these actions should be placed in the first frame of the Actions layer.

// calculate circle hit area
C_hitLeft_x = circleHit._x - 6;
C_hitTop_y = circleHit._y + 6;
C_hitRight_x = circleHit._x + 6;
C_hitBottom_y = circleHit._y - 6;

drag_me.onPress = function() {

startDrag(this, false);

}

drag_me.onRelease = function() {

stopDrag();
// if drag_me is in the circle hit area then make it black
if (this._x < C_hitRight_x && this._x > C_hitLeft_x && this._y < C_hitTop_y && this._y > C_hitBottom_y) {

this.gotoAndStop(5);

}
else {

this.gotoAndStop(1);

}

}

drag_me.onReleaseOutside = function() {

stopDrag();

}

Your done, thank-you for participation in the My Flash Resource Tutorial.

Comments are closed.

Flash Gaming Advancements

by

In recent years, the demand for flash online gaming apps has exploded. Flash enables many gaming sites the ability to offer a "live" online gaming experience, saving the user the trouble of downloading software, complicated sign-up processes, or wasted time. Though flash casino games are generally not quite as embellished as their downloadable counterparts, they are, for the most part, increasing in quality everyday as new programmers, graphic designers, and marketing companies embrace this technology. Some sites, such as www.payspark.com, are entirely built in Flash. This website is a European E-Wallet that enables its users to interface with virtual banking privileges, all built upon an amazing flash platform. As a result, it is easy to see how Flash technology and the strict privacy needs of banking can be used together to produce a workable product.

By far, the most widespread use of Flash in the online gaming sector is among online casino businesses. Customers impatient to wait for software downloads can jump right into playing at these online casinos, which take advantage of Flash's rich graphic interfaces to create a truly unique gaming experience. Still other online casinos prefer to use Flash in their affiliate and banner marketing campaigns. Top software provider MicroGaming, known the world over for quality and fairness, definitely leads the pack when it comes to the most realistic and reliable software. Flashship casino brand Lucky Nugget casino boasts some of the best graphics on the web. The insta-play Flash Casino is flawless and beautifully engineered. Additionally, European casino CasinoEuro built most of its homepage using Flash and Action Script 3 language integration, allowing users from multiple countries speaking different languages to play online. Flash graphics and transition effects are highly captivating, much more so than their animated .gif counterparts. The ability to track users clicking on such banners has also allowed most online casinos to use CRM models to enhance customer retention and to analyze user trends on both a broad and micro scale.

Increasingly, Flash is also finding a new home in the online sportsbook market. Many websites offering sports gambling alternatives take advantage of colorful flash banners as a way to attract sports bettors, and also as a way to show off to the customer. Sports Betting websites rely on mitigating risk, but also by landing a critical mass of customers through marketing campaigns. As a result, those interested in NFL betting - the most popular sport among bettors, can be relatively assured that they truly "get what they par for". Next to the NFL, basketball betting is the next most popular draw. Web designers at many online sports betting don't have much time to create original imagery. So, many stock photo companies are beginning to offer Flash images for savvy web designers looking to gain an edge. Many marketing companies relish in the fall NFL Betting season, and spend countless hours during the spring creating the right campaigns to boost ROI. Also, the demands of the football betting season require high end servers to populate the web with all the Flash images. Flash graphics definitely draw more bandwidth than .gif images, but as server technology improves and communication infrastructures advance, soon .gif images will be history.

In the end, because the online casinos vertical is so competitive, it comes down to getting to most bang for the buck. Using flash graphics with eye-catching slogans, images, and animation truly allows online casinos the ability to capture a user's interest immediately.

My Flash Resource - A continually growing collection of tutorials, thoughts and interests of a Flash Animator and/or Developer.

categories:

other:

New Feedburner Feed!


Feel free to syndicate.

Learning Material

Flash Resources:


Listed on BlogShares