Archive Page 2

15
Feb

FileReference onComplete is not fired on Mac OS / 404 error / IO error

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

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

Found this useful? How about buying me a coffee - simply click here.

14
Feb

Getting List of Child MovieClips in AS3

Here is how you find all the movieclips inside an object in as3

var desc:XML = describeType(my_mc);
for each (var node:XML in desc.variable) {
    if (node.@type == "flash.display::MovieClip") {
        if (my_mc.getChildByName(node.@name.toString())) {
            trace("child mc found");
        }
    }
}

Found this useful? How about buying me a coffee - simply click here.

13
Feb

load external files / assets with AS3

This example shows you how to load and external asset (file) in AS3. The files can be a swf, jpg, gif or png.

This particular example loads a jpg called loademe.jpg and attaches to the stage

Load Asset / external files example
// loadAsset.as
package {
	import flash.display.*;
	import flash.net.URLRequest;
	import flash.net.URLLoader;
	import flash.events.*;

	public class loadAsset extends Sprite{

		private var _loadPath:String
		private var _loader:Loader;

		// Constructor
		public function loadAsset(){
			// Create the loader
			_loader = new Loader();

			// Add event listener that tells us when the
			// asset can be safely accessed
			_loader.contentLoaderInfo.addEventListener(Event.INIT, displayAsset);

			// Create new URLRequest
			var urlRequest = new URLRequest("loadme.jpg")

			// Start the asset load
			_loader.load(urlRequest);
		}

		// Display the asset once the load is complete
		private function displayAsset(ev:Event){
			// it to the DisplayObjectContainer
			addChild(_loader.content);
		}
	}
}

To load the asset/file you need to open the flash file and place this AS in the timeline

import loadAsset;
addChild(new loadAsset());

Found this useful? How about buying me a coffee - simply click here.

12
Feb

Mouse Event - click

In AS3 mouse event a handled differently than in AS2. Here is the general procedure for adding a click event to a object.

Full code after the jump.

Mouse Event - click
// 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.CLICK, clickListner);

function clickListner(ev:MouseEvent):void{
	trace("Circle Clicked");
}

Found this useful? How about buying me a coffee - simply click here.

11
Feb

Mouse Event - up

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”);
}

Found this useful? How about buying me a coffee - simply click here.

10
Feb

Mouse Event - over

In AS3 mouse event a handled differently than in AS2. Here is the general procedure for adding a mouse over event to a object.

Mouse Event - over
// 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_OVER, clickListner);

function clickListner(ev:MouseEvent):void{
	trace("Mouse Over Circle");
}

Found this useful? How about buying me a coffee - simply click here.

10
Feb

Creating ActionScript 3.0 components in Flash

It’s so massive that its currently only available as a series of PDFs. It’s the article everyone has been waiting for from Adobe:

Create ActionScript 3.0 components in Flash CS3 Professional

Found this useful? How about buying me a coffee - simply click here.

09
Feb

removeChild and removeChildAt memory fun

removeChild() does not always remove the object from memory. removeChild() and removeChildAt() actually only remove the object from their parents DisplayObjectContainer. If the removed object is referenced by a variable or some such other thing the object will still persist in memory until the variables are cleared or set to null.

for example we draw a circle and attach it using the following

var cir:Shape = new Shape();
cir.graphics.lineStyle(1);
cir.graphics.beginFill(0xFF0000);
cir.graphics.drawCircle(100,100,50);
parent.addChild(cir);

now if we use the removeChild() to delete the shape

parent.removeChild(cir);

It is now longer viewable in the movie, but because it is referenced by the variable cir, the object will actually still persist in memory.

so you can re-add the shape by using

parent.addChild(cir);

If you wanted to totally remove the shape from memory you would need to change or assign a null to every var that references the shape, in our case you would do this

parent.removeChild(cir)
cir = null;

Even then it doesn’t remove the shape from memory it is now just eligible for garbage collection. (more about grabage collection another day). But for all intsive purposes it is gone.

Found this useful? How about buying me a coffee - simply click here.

08
Feb

Introduction to Flash’s Drawing API

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,0×000000,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

Found this useful? How about buying me a coffee - simply click here.

07
Feb

Error (#2148) Loading XML with Flex2 - Security Error

I had this problem and thought you would all like to know….. I was trying to load a local xml doc and this solution worked for me.

Posted on January 11th, 2007 by polyGeek

Error (#2148) Loading XML with Flex2

I was running through a simple tutorial for loading XML into Flex and displaying it in a DataGrid when I got the following error:

[RPC Fault faultString=”Error #2148: SWF file file:///C:/Documents and Settings/…/My Documents/xmlParsing/bin/xmlParsing.swf cannot access local resource Blades.xml. Only local-with-filesystem and trusted local SWF files may access local resources.” faultCode=”InvokeFailed” faultDetail=”null”]

If I go into the bin folder and launch the SWF directly then everything loads and works correctly. That right off is a tip that it’s probably a security issue. Sure enough. With a little research I found it.

  • In the Navigator panel Right-click and select Properties
  • In the lefNav select Flex Compiler
  • In the Additional compiler arguments: field add the following argument: -use-network=false

So my arguments read: -locale en_US -use-network=false

It would seem that this setting has to be made for each project.

Stupid security settings. :-)

When I Googled this problem I only got three hits back. My guess is that this will be a common problem so it wouldn’t hurt for others to duplicate this solution to make it easier for others to find.

Found this useful? How about buying me a coffee - simply click here.





Close
E-mail It