If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
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.
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.
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.
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.
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.
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.
Here the first in a series of installments that will shed some light on Enterprise Flex RIA’s
“In this installment of the series Anatomy of an Enterprise Flex RIA we’re doing a little grunt work and installing some tools we’ll be using later. Download them and read up a bit on what they do. These tools are some common “enterprise software” development tools that we’ll need to get the example software up and running.
In this series, we’ll look at a small application that integrates the technologies of LCDS and EJB 3.0, and we’ll cover some timesaving tools as well as discuss how to use them to achieve a lightweight development environment for integrating an RIA with an enterprise environment. Ready to get started?”
http://www.insideria.com/2008/01/anatomy-of-an-enterprise-flex.html
Found this useful? How about buying me a coffee - simply click here.
You can place this code in an AS3 document or a custom class, your choice. Thanks to Matt for the snippet Full code after the jump.
AS3 click and drag example
function initDragger(mc:MovieClip):void
{
mc.addEventListener(MouseEvent.MOUSE_DOWN, function (e:MouseEvent):void
{
e.currentTarget.startDrag();
});
mc.addEventListener(MouseEvent.MOUSE_UP, function (e:MouseEvent):void
{
e.currentTarget.stopDrag();
});}
// Set up drag
initDragger(cir_mc);
Found this useful? How about buying me a coffee - simply click here.
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:
- Scenes can make documents confusing to edit, particularly in multiauthor environments. Anyone using the FLA document might have to search several scenes within a FLA file to locate code and assets. Consider loading content or using movie clips instead.
- Scenes often result in large SWF files. Using scenes encourages you to place more content in a single FLA file and hence, larger documents to work with and larger SWF files.
- Scenes force users to progressively download the entire SWF file, even if they do not plan or want to watch all of it. Your user progressively downloads the entire file, instead of loading the assets they actually want to see or use. If you avoid scenes, the user can control what content they download as they progress through your SWF file. This means that the user has more control over how much content they download, which is better for bandwidth management. One drawback is the requirement for managing a greater number of FLA documents.
- Scenes combined with ActionScript might produce unexpected results. Because each scene timeline is compressed onto a single timeline, you might encounter errors involving your ActionScript and scenes, which typically requires extra, complicated debugging.
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
Found this useful? How about buying me a coffee - simply click here.
I Have just posted up a code snippet that validates general email addresses in AS2. [Update] - Click here for the AS3 Email Validation Code
Full code after the jump.
function validateEmail(emailStr:String) {
var errorCount:Number = 0;
//check to see if there are at least two chars be for the @ symbol
if (emailStr.indexOf("@")<2) {
errorCount++;
}
//check that the @ is not within 2 chars of .
if (emailStr.lastIndexOf(".")<=(emailStr.lastIndexOf("@")+2)) {
errorCount++;
}
//check length eg min aa@bb.cc
if (emailStr.length<8) {
errorCount++;
}
//check there is only one @
if (emailStr.indexOf("@") != emailStr.lastIndexOf("@")) {
errorCount++;
}
// return a T/F to the flash file
if (errorCount == 0) {
return true;
} else {
return false;
}
}
//to use it
if(validateEmail(email.text)){
trace("EMAIL VALID");
}else{
trace("EMAIL NOT VALID")
}
Found this useful? How about buying me a coffee - simply click here.