If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
This is a simple function that returns a random value within a range.
function randomNumber(rangeMax:int = 1, rangeMin:int = 0):int { return Math.round(Math.random() * (rangeMax - rangeMin) + rangeMin); } trace(randomNumber(13, -3)); // Returns a random number between -3 and 13. trace(randomNumber(50)); // Returns a random number between 0 and 50. trace(randomNumber()); // Returns 0 or 1 as random number.
Returns the number of words in a string.
function wordcount(string:String):Number {
var wrdArray:Array = string.split(" ");
for (var i = wrdArray.length; i>0; i--) {
if (wrdArray[i] == "") {
wrdArray.splice(i,1);
}
}
return wrdArray.length;
}
trace(wordcount("This will count the number of words"));A While ago we had an interesting problem with file flash uploaders on Macs. It turns out it doesn’t work. But we have found the way. So here is how we solved the undocumented feature
1. Firstly ensure that you explicitly load the cross domain policy file.
2. Make sure you escape all the characters, Macs hate spaces.
3. And the most important you need to send empty response from upload server-side script.
In php, you would just do
echo (”");
after file-upload code. In ASP, you can do
Response.Write (”").
In Java servlet, you can do:
response.getWriter().println(”");
response.getWriter().flush();
That’s all, now onComplete event should trigger on Mac’s Adobe Flash Player 8.
But if sending “” dosent work try “ “ or “1” – we found that sending 1 was the best option.
Hope this shines some light on a frustrating problem
Using Actionscript you are able to draw lines in a movie. This is achieved by a bunch of drawing methods attached to the Movie Clip Class.
What we are going to do today:
This is the first installment of a series of flash drawing tutorials. Today we are just going to have a brief introduction and overview to the drawing methods in the Movie Clip Class. We will create a basic drawing app that will let you draw on the stage at run time.
In future tutorials we will explore into colors, gradients, and much more
Introduction to the methods that we will use today:
lineStyle()
Before drawing any lines in a movieclip you must set a linestyle for that movieclip
Sintax
my_mc.lineStyle(thickness, color, alpha)
moveTo()
All movieclips hold a drawing position/coordinate where the line will start. When a movieclip is instance is created on stage the drawing position is set to 0,0 but moveTo() can change the drawing position.
Syntax
my_mc.moveTo(100,100)
lineTo()
This is the one that will do most of the work for us today. This class draws a line from the moviesclips drawing position, in the lineStyle to the position in the method
Syntax
my_mc.lineTo(200,200)
Lets Create the App.
In this app when you click and drag on the stage a line will be drawn, just line in Photoshop or any drawing application. In future tuts we will add color, brushes, and fill shapes, clear stages and event attempt to save our image to a jpg. But today we will just get the basics sorted.
Step 1
First thing first we need to detect when the mouse is down/pressed. So open a new flash doc and add the following code to the first frame of the main timeline
stop();
var isDown:Boolean = false;
onMouseDown = function(){
isDown = true
}
onMouseUp = function(){
isDown = false
}
This code will allow us to tell is the mouse is down or up. As if it is down we will be drawing on the stage
Step 2
We will create a canvas for us to draw on which is just a movieclip. You also draw straight onto the root of the stage but I prefer the movieclip way.
Add the code in bold
stop();
var isDown:Boolean = false;
var mcCanvas:MovieClip = this.createEmptyMovieClip("canvas_mc", this.getNextHighestDepth())
onMouseDown = function(){
isDown = true
}
onMouseUp = function(){
isDown = false
}
Now we have a moveclip called canvas_mc that we can draw on.
Step 3
Now that we have the canvas to draw on we need to adjusts its drawing cords to the mouse position every time the mouse is pressed
Add the code in bold
stop();
var isDown:Boolean = false;
var mcCanvas:MovieClip = this.createEmptyMovieClip("canvas_mc", this.getNextHighestDepth())
onMouseDown = function(){
isDown = true
mcCanvas.moveTo(_xmouse,_ymouse)
}
onMouseUp = function(){
isDown = false
}
Step 4
Now to the part that will actually make this app draw. We are going to use onMouseMove to draw on the canvas, you could also use onEnterFrame.
Add the code in bold
stop();
var isDown:Boolean = false;
var mcCanvas:MovieClip = this.createEmptyMovieClip("canvas_mc", this.getNextHighestDepth())
onMouseDown = function(){
isDown = true
mcCanvas.moveTo(_xmouse,_ymouse)
}
onMouseUp = function(){
isDown = false
}
onMouseMove = function(){
if(isDown){
mcCanvas.lineStyle(2,0x000000,100)
mcCanvas.lineTo(_xmouse,_ymouse)
}
}
When the mouse moves we test to see if the mouse is down and if it is we when set the line style and draw the line.
Test the move and have a play
That’s it… simple
Have a play with colors and brush sizes. Also see if you can create a button that will clear all the lines drawn…
Tip you don’t need to remove or remake the canvas. Have a look in the help
I got asked the other day why don’t we use scenes?
Before getting into using scenes read below, this is a hotly contested area but is suggested best practice by adobe to steer away from scenes. Read below for adobes official thoughts and my own on scenes in flash…
Using Scenes
Using scenes is similar to using several SWF files together to create a larger presentation. Each scene has a timeline. When the playhead reaches the final frame of a scene, the playhead progresses to the next scene. When you publish a SWF file, the timeline of each scene combines into a single timeline in the SWF file. After the SWF file compiles, it behaves as if you created the FLA file using one scene. Because of this behavior, avoid using scenes for the following reasons:
There are some situations where few of these disadvantages apply, such as when you create lengthy animations. If you create lengthy animations, you might find it adventageous to use scenes. If disadvantages apply to your document, consider using multiple FLA files, movie clips, or screens to build an animation instead of using scenes. For more information on using screens, see Working with Screens in Flash Help or the Flash 8 LiveDocs (Using Flash > Working with Screens).
Basically I think scenes are the devils spawn
Instead I would suggest that you break your file into manageable flash files (chucks) e.g make separate swf files. This will make it easier to create, edit, code and in end manage.
Hope this helps clear some things up