Recently I set myself to compile an Actionscript3 project by hand using the mxmlc tool on the command-line and wanted to share that in case you ever need to do something similar. It's no biggie and it might be useful for a number of things (making automatic builds, building on machines without the Flash IDE or Flash Builder, etc).
1. Open a console and go to the directory of your project
2. Export the PATH to include the flex sdk binaries, e.g. run:
Note: For those of you that don't know it already, the Flex SDK is a free of charge Actionscript3 library that allows the development of Flex & Actionscript 3-based applications, without the need to purchase Flex Builder/Flash Builder.
This week I finally had a project that involved 3D (about time too).
Since it involved interacting with 3D models, using Flash 10 was out of the question. So I opted to go with papervision, instead of away3D or alternativa3D, since this was the engine we where more accustomed to.
Sometime along the development of the application I came across the need to convert 3D coordinates into 2D screen coordinates and also the opposite. It's nothing new and it's already implemented in papervision, but since it took me a little while to find it, I decided to share it.
Getting the 2D Screen coordinates from a DisplayObject3D
Since papervision 2.0 that every DisplayObject3D has a property called "screen", that will return the coordinate of the object on screen. Whenever I tried to access the screen property the number3D I got back was always (0,0,0). Probably because it's an expensive operation and it's something you only need sporadically, papervision will not calculate this automatically. You need to ask papervision yourself to calculate this coordinates. To do so, just use the "calculateScreenCoords" of the do3d
myDisplayObject3D.calculateScreenCoords(camera)
Now when you try to access the "screen" property you will get the number3D with the screen coordinates for your DisplayObject3D.
Getting the 3D coordinates from a 2D point (x,y)
For this one I found a great post by zupko that tells you exactly what you need to do.
In a nutshell, you need to take your 2D coordinates (x,y) and convert them into a direction vector. Having the vector and the camera position you can create a ray (line) that will go from the camera into infinity. Next you need to specify the Z, or in another words, where do you want to stop on that line. Zupko uses a 3D plane to do that using the "getIntersectionLineNumbers"
Just remember papervision's 3D Zero (0,0,0) is at the center of the screen and not on the upper left corner like the 2D Zero (0,0)
A potential vulnerability has been identified in Adobe Flash Player 10.0.12.36 and earlier that could allow an attacker who successfully exploits this potential vulnerability to take control of the affected system. A malicious SWF must be loaded in Flash Player by the user for an attacker to exploit this potential vulnerability. Additional vulnerabilities have been addressed in this update. Adobe recommends users update to the most current version of Flash Player available for their platform.
More information about this security vulnerability is available at:
I start working on a photo library in papervision, so I look around I got an example from flashEnabledBlog, one of the problems was that the example was in flash cs3 and I need it in flex actionscript project, the other one was that the example was done with old papervision and tweener versions, so I had to port it. It’s a good start if you have to do something like it. I Include lasted versions of Tweener and Papervision in the zip file, you just have to run it.
If you remember in as2 we had _root which let us access to methods and variables in the root of the project and refer to absolute paths, I thought that as3 didn’t have _root propriety, but I was wrong. root property can be useful if you want to share some value to all the classes in the project, add events to main class that call methods declared inside the class where we are working on or call generic methods declare in root class.
To use root propriety the class that you are working on most extend a DisplayObject (Sprite,MovieCLip,etc…) because you have to add the class to the parent class. And note, you can’t use the root propriety in the constructor method, because the addChild haven’t been process yet! Well let’s stop writing and see some code:
Main.as
In the Main class I’m declaring a variable named myValue which I did the proper sets and get. I am declaring two classes, in one of them I will set the value at the Main class and in the other I will get that value back. I’m also creating a movieClip just for test purposes.
ExampleClass.as
In ExampleClass I’m setting myValue that is propriety of the Main class with some text and I’m tracing the movieClip that I create in the Main Class.
AnotherClass.as
In AnotherClass I’m tracing the myValue propriety. So the result should be: [object MovieClip]
This value is inside the Main Class
So it works ok, you only have to be carefull not refer root inside the constructor method, have the certain that you already addChild the class when you are referring to root and that the class extends a display object. If you do that, you can too have access to stage propriety, let’s check the next example:
ExampleClass.as
The result should be or stage width.
Another way to access to main proprieties, methods, etc… is with static members. In the next example I’m declaring a static property in the main class and setting and trace the value of it in the example class.
Main.as
ExampleClass.as
The result should be “Hello Word!â€, if you didn’t know this, read some books about object oriented programming and static members.
Another way to do the same thing is to pass the instance of main class as an argument to the other classes.
Main.as
Example.as
There are still another ways to access to the Main class code. I don’t know which techniques are more correct, I usually use them all depending in what I need. I hope I help someone.
Since 99.9% of the work we do is Flash, we pretty much use flex builder to develop Actionscript Projects. One of the things I really wanted to have was bindings. Here's how to use Flex Bindings in Actionscript only projects.
Remember that the Flash framework (textfields, movieclips, sprites, etc) doesn't dispatch the data-binding event. This means that pretty much the only things you can bind are variables.
Make sure you add the flex framework.swc to your project Library Path to have access to the mx.binding.util class.
ChangeWatcher:
Acts like the watch on AS2. It watches a variable for changes and when something happens fires an event. Make sure you call the canWatch to ensure that you can watch it!
There are 3 ways to specify the second parameter, the chain.
A String containing the name of a public bindable property of the host object.
ChangeWatcher.watch(this, "myvar", handler)
An Object in the form: { name: property name, access: function(host) { return host[name] } }. The Object contains the name of a public bindable property, and a function which serves as a getter for that property.
A non-empty Array containing any combination of the first two options. This represents a chain of bindable properties accessible from the host. For example, to watch the property host.a.b.c, call the method as: watch(host, ["a","b","c"]
BindingUtils.bindProperty
Works pretty much the same way as the watch, but instead of having to handle and event it allows you to immediately bind two properties one-way.
The first two parameters are for the the target, the second parameters are the triggers.
We're proud to announce that Dreaming has published a few tutorials over at The Tech Labs, these tutorials are exclusive and can be accessed at: http://www.thetechlabs.com/
They include an air contact manager, and two sound equalizer how-tos with one of them showing how to get those cool pv3d equalizers.
+ Help the community
+ Explore the Flash platform
+ Create a better world
+ Research and play
Startups
We're looking for stories about startups using Flex/Flash technology. Drop us a quick e-mail or mention it to us via our Twitter account @dreaminginflash, thanks!