Archive for May, 2009
One last step in creating
Posted by Admin in Uncategorized on May 31st, 2009
One last step in creating a custom cursor is to make sure that it appears on top of all the other movie clips. To switch the level of a movie clip, you can choose Modify, Arrange, Bring to Front. However, this only moves the movie clip above all other static movie clips on that layer. It does not move it above movie clips on other layers. Even if you placed the cursor movie clip in the top layer, it could still be behind movie clips created with ActionScript using the duplicateMovieClip and attachMovie commands.
To ensure that the movie clip is above all else, you will want to use the swapDepths command to bring the movie clip the very front.
The swapDepths command takes a movie clip and places it at a new level. A level can be any integer: 0, 1, 10, 9999, anything. If anything was at that level previously, it will now be at the former level of the other movie clip.
When you use the duplicateMovieClip or attachMovie commands, you specify a level for the new movie clip to reside. As long as these numbers are less than the level of the cursor movie clip, the cursor will always be on top. For instance, this command virtually ensures that the cursor movie clip stays on top:
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
By first using Mouse
Posted by Admin in Uncategorized on May 30th, 2009
By first using Mouse.hide() and then making a movie clip follow the cursor location, you can effectively create a custom cursor.
This cursor can be anything you want: your own stylized arrow, a hand, or something that fits the movie you are working on.
If you want to switch from using a custom cursor back to the regular cursor, all you need to do is to use the Mouse.show() command to make the regular cursor visible again.
How about an animated cursor? This is just as easy to create; you simply need to place the animation across multiple frames of the movie clip. No additional ActionScript is needed. Using an animated movie clip is just as easy as using a static one.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
Hour 13. Rollovers
Posted by Admin in Uncategorized on May 29th, 2009
Some common interface elements are used throughout computer applications. In the next few chapters, we will look at things such as scrolling text fields and pop-up menus. In this chapter, we will look at simpler interface elements: the cursor and the rollover.
In this hour, you will:
Learn how to create a custom cursor
Learn how to create rollovers
Build a quick reference application with rollovers
Creating Custom Cursors
In Hour 7, “Moving and Changing Movie Clips,” you learned how to set a movie clip’s location to the location of the mouse with the _xmouse and _ymouse properties. While the movie clip remains at the location of the cursor, it is not useful as a cursor because the real cursor stays visible. We can change this, however, by getting rid of the cursor altogether with the Mouse.hide() function.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
Workshop
Posted by Admin in Uncategorized on May 28th, 2009
The quiz questions are designed to test your knowledge of the material covered in this hour. The answers to the questions follow.
Quiz
1: If you set the month of a Date object to 6, which month is that?
A1: July. Months are numbered starting with 0, so month 6 is the seventh month.
2: What are the two commands that can change the color of a movie clip?
A2: The setRGB command can apply a color to a movie clip’s Color object. The setTransform command can apply a complex color alteration to the movie clip Color object.
3: How many ways can an element be removed from an array?
A3: Four. The pop, shift, and splice commands all remove items from an array.
4: What is the difference between push and unshift?
A4: The push command adds an item to the end of an array. The unshift command inserts an item at the start of the array.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
If I can’t trust the user’s compute
Posted by Admin in Uncategorized on May 27th, 2009
If I can’t trust the user’s computer time, how can I get a time that I trust?
A3: Only server time is trustworthy, and then only if you trust your server. In most cases, for instance, in an e-commerce application, you don’t need to trust the time on the client’s machine because the server will apply its own time when the transaction is made. However, you can always set up your server to pass the time to the Flash movie via one of the external data methods discussed in Hour 10, “Creating and Controlling Text.”
Q4: Can arrays store items of different types? Can an array contain numbers and strings?
A4: Yes, an array can store data of mixed types. For instance, suppose that you had an array that stored mouse location and clicks. Most of the elements might be x and y locations, but some might be the string “click” to signify that a click was made at that point. You just have to make sure that the code that reads the array can handle what comes
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
Q&A
Posted by Admin in Uncategorized on May 26th, 2009
What if I have a variable named the same thing as a movie clip? How do I differentiate between them in my code?
A1: You can’t. For example, if you have a movie clip instance at the root level named mine and you create a variable at the root level named mine, you will not be able to access that movie clip instance. Always use different names for movie clip instances and variables.
Q2: If I have a movie clip that uses all sorts of colors, how does setting the Color object of the movie clip affect it?
A2: It changes each color depending on how it relates to the Color object. It is difficult to predict unless you are very good with colors. However, you can test the changes by choosing Advanced color in the Properties panel and then clicking the Settings button. You can then adjust the numbers and see the changes live.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
Summary
Posted by Admin in Uncategorized on May 25th, 2009
By creating custom variable objects, you can better organize your variable values and pass along large amounts of information more easily.
You can also use built-in objects like the Color object and Date object. The Color object allows you to change the color of a movie clip. The Date object allows you to get the current time and access different aspects of a moment of time.
Arrays are a powerful part of programming that allow you to store large lists of similar data. You can manipulate arrays with all sorts of ActionScript commands, such as push to add a new item and pop to get the last item. You can also modify and sort arrays.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
This new object will be pushed
Posted by Admin in Uncategorized on May 24th, 2009
This new object will be pushed onto the array. This means that the value goes on the end of the array. If more than 10 items are in the array, the first and oldest item is removed.
The array now holds the last 10 locations of the mouse, in order from oldest to most recent. It sets each one of the 10 movie clips to one of these locations. The _alpha of each movie clip also changes to reflect the age of the location. Its oldest location will be at 10 percent, whereas the most recent will be at 100 percent.
Test the movie, or try 11cursortrail.fla to see it in action. As you move the cursor around, you will see the little movie clips follow it. Figure 12.2 shows what this should look like. You can make the trail closer by increasing the frame rate of the movie. You can also try to see what happens when you use 20, or even 100 movie clips rather than 10.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
Create an Actions
Posted by Admin in Uncategorized on May 23rd, 2009
Create an Actions movie clip to hold the scripts, as in the previous task. Place it off the visible area of the workspace.
Attach this script to the Actions movie clip. It starts by creating 10 instances of the Cursor movie clip. Then it makes an array named trail.
onClipEvent(load) {
// create 10 cursor followers
for(var i=0;i<10;i++) {
_root.attachMovie(”cursor”,”cursor”+i,i);
}
// start the array
trail = new Array();
}
With every frame that passes, the new location of the mouse will be put into a simple custom object. This object will have x and y properties with values that correspond to the _root._xmouse and _root._ymouse properties of the movie.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
Task: Dragging with Trails
Posted by Admin in Uncategorized on May 22nd, 2009
In this next example, we’ll store a series of locations in an array. As the mouse moves, we’ll push the current location onto the array and shift the oldest location off of the array. That way, we’ll maintain a list of the 10 most recent positions of the cursor.
We’ll use this information to set the locations of 10 movie clips. The result will be a trail of movie clips that follow the cursor around.
Start with a new movie.
Create a small movie clip that will be an element of the tail. It can be just a very small circle. Leave this movie clip in the Library, but delete it from the screen. Set its Linkage properties so that it exports with the movie and uses the linkage name Cursor.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours


Recent Comments