If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
So it would turn out that flash CS4 cannot handle large projects out of the box. It took me a while to find the solution that is why I am republishing. This fix was originally posted on negush Their post was originally about fixing the 5005: Unknown error optimizing byte code. But what I found out later after swapping to a new macihine is that the fix below also fixes the “You cannot debug this SWF because it does not contain ActionScript”. What I think happens is the compiler runs out of memory in a big project and instead of erroring shows you the stuipid non helpful error.
But the fix below should solve the two issues (5005: Unknown error optimizing byte code and You cannot debug this SWF because it does not contain ActionScript)
Fix - windows (sorry i dont know how to change environmental vars on mac)
my computer -> properties -> advanced -> environment vars -> then make a new var like this
JAVA_TOOL_OPTIONS
and its value
-Xmx128M or -Xmx256M
Another solution on the web is to delete the .aso files generated by Flash (Control -> Delete ASO Files) .
If someone knows how to set the fix on a mac can they please post a comment
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
In AS3 mouse event a handled differently than in AS2. Here is the general procedure for adding a mouse up event to a object.
Mouse Event - up
// you will need a movieclip on the stage with an instance name of cir_mc
// or just download the file above (www.flashcs.org)
cir_mc.addEventListener(MouseEvent.MOUSE_UP, clickListner);
function clickListner(ev:MouseEvent):void{
trace(”Mouse Up”);
}
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
These are two useful formulas that you will use more often than not.
degrees to radians
var degrees:Number = radians * 180 / Math.PI
radians to degrees
var radians:Number = degrees * Math.PI / 180
So it would seem that when you publish your movies in flash, removeMovieClip() doesn’t seem to work properly or at all.
This is because you are more than likely using getNextHighestDepth() which is supposably perfectly fine. But in certain cases such as using v2.0 components or buttons this will cause problems. The reason is that when you use components the Flash DepthManager class automatically reserves the highest upper and lower depths available to Flash (-16383,1048575). So if you have a component in your fla and you call getNextHighestDepth() it will return 1048576 – this is now an out of range depth for removeMovieClip() making it unable to remove the clip. Also the call will fail silently (making it hard to debug)
Work Around Provide by macromedia
Use unLoadMovie() instead ofremoveMovieClip(). – I still have problems, but it might work for you.
Swap the depth of the movie clip to a level at or below 1048575 before doing removeMovieClip() – With a complicated movie can get interesting to sort sometimes
The easiest way I have found is to manage the depths manually, this approach is extremely easy and doesn’t cause any issues
var nDepth:Number = 100
var createEmptyMovieClip(“myClip_mc”, nDepth++);
Hope this shines some light on what can be an extremely frustrating problem.
Read some more about it here
http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_19435
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