I recently had trouble with Flex truncating the label on some but...
It was a particularly aggravating affair, playing with the padding and the width which had no apparent effect. After hours of searching the net and finding nary a shred I discovered that there was a simple fix.
Simply changing the label placement property of the button to 'bottom' had the desired effect rendering the label correctly.
Ahhhhh, much better.
2009-09-24
Flex - Button label truncation problem
2009-08-17
Custom Events in Action Script
You have an custom actionscript 3.0 class and it does all sorts of great thing, but now you want other people to be able to use it. There are many ways to do this but for this example I am going to create a custom event. Lets get started.
First add the following imports to your class.
import flash.events.Event; import flash.events.EventDispatcher;
Then add the metadata about the custom event, the event in this example is called customEvent.
[Event(name="customEvent", type="flash.events.Event")]
Next copy and paste the following code anywhere into your class this is used to add the functions need to create event listeners and dispatch events.
private var disp:EventDispatcher;
public function addEventListener(type:String, listener:Function, useCapture:Boolean=false,
priority:int=0, useWeakReference:Boolean=false):void {
if (disp == null) disp = new EventDispatcher();
disp.addEventListener(type, listener, useCapture, priority, useWeakReference);
}
public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void {
if (disp == null) return;
disp.removeEventListener(type, listener, useCapture);
}
public function dispatchEvent(event:Event):void {
if (disp == null) return;
disp.dispatchEvent(event);
}
Next you need to add the code to fire your custom event to do this add the following code to the function you want to fire the event.
var deviceDataEventObject:DeviceDataEvent = new Event("customEvent");
dispatchEvent(deviceDataEventObject);
OK you custom class can now fire your custom event all you need to do is set up a event listener in the calling class, use this code.
customClass.addEventListener("customEvent", yourFunction);
private function yourFunction(event:Event):void{
//Do Something here
}
Thats it you are done simple huh?
2009-07-30
Free Flex Visual Studio Plug-in
- Flash Develop - "Release notes and download" link, then towards the bottom of the page redirected page.
- Java SE Runtime Environment (JRE) - download button under the table heading (Java SE Runtime Environment (JRE).
- Flex SDK - "Free Adobe Flex 3 SDK" link.
- Tofino Visual Studio Plugin - "Download Tofino [version] without Flex SDK" link.
[version] is a place holder for the current version of the file you downloaded):
- Extract the Flex SDK (
flex_sdk_3.zip) to "C:\Flex\3\". - Install the visual studio plugin (
EnsembleTofinoWithoutFlexSDK.[version].msi) by double clicking it. - Open Visual studio
- Open the Options Windows
- Check the "Show all settings" checkbox if its there
- Go to Projects > Flex Projects
- Set the Flex 3 SDK location to "C:\FlexSDK\3\|
For more info on how to use the plug-in there is an article at developer fusion.
2009-07-29
Controlling Flex With Javascript
For work I had to do a proof of concept to show that I could control flex using javascript and here is is with the source, if you want to do it follow this article.
I did have one problem tho and that was i was using Flash Develop and there is no "Create Ajax Bridge." menu option, luckily this can be solved pretty simply just by copying the the files from you sdk directory to you project they are located in
[sdk]\frameworks\javascript\fabridge\src\bridge\.
2009-07-22
Free Flex IDE
Installing First you need to download all the required files listed below:
- Flash Develop - "Release notes and download" link, then towards the bottom of the page redirected page.
- Java SE Runtime Environment (JRE) - download button under the table heading (Java SE Runtime Environment (JRE).
- Flex SDK - "Free Adobe Flex 3 SDK" link.
- Design View plugin - "Download Plugin" link.
- Design View Air Package - "designview.air" link.
- Debugger Plugin - "FlexDbg.zip" link.
Now you have a directory full of downloads it is time to start installing(please note [version] is a place holder for the current version of the file you downloaded):
- Run the installer(
FlashDevelop[version].exe) for Flash Develop and and leave everything as the defaults. - Install the Java SE Runtime Environment (
jre-[number]-windows-i586.exe). - Extract the Flex SDK(
flex_sdk_3.zip) to "C:\Flex\3\". - Install the Design View AIR app(
designview.air) by double clicking it. - Open the Design View plugin(
FlexDesignView-[version].zip) and copy the contents of "Data" to "C:\Program Files\FlashDevelop\Data\" and the contents of "Plugins" to "C:\Program Files\FlashDevelop\Plugins\". - Extract the Debugger Plugin(FlexDbg.zip) to "
C:\Program Files\FlashDevelop\Plugins\"".
Now Everything is in installed all you need to do is set up flex in Flash Develop:
- Open the Flash Develop(
Start > Applications > Flex Develop > Flex Develop). - Once the application is opened press
F10or go to "Tool > Program Settings" to open the Program Settings. - Click on AS3Content button (1. in the image below).
- Then set the "
Flex SDK Location" (2. in the image below) to "C:\Flex\3\". - Click Close, and enjoy Flash Develop.
Update: as requested here are some screen shots with FlashDevelop in both Source and Design Views.
2009-07-20
Solved It!
view.addEventListener(Event.ADDED_TO_STAGE, zoomCamera);
2009-07-17
Adding Interactivity to Papervision 3D
There are two types of Interactivity in this demo the first is controlling the camera and the second the 3D Animation i.e. making the panels spin when you click them.
Controlling the Camera
Controlling the camera is pretty simple in this example all you need to do is track the mouse movement and translate it into camera movement.
To do this simply add the following code into your Event.ENTER_FRAME listener, where view is the Papervision View you are using.
view.camera.x += (((stage.mouseX - (stage.stageWidth * .5)) * 2) - view.camera.x ) * .02; view.camera.y += (((stage.mouseY - (stage.stageHeight * .5)) * 2) - view.camera.y ) * .02;
Controlling 3D Animation The easiest what to control 3D animation is to use tweener. Basically Tweener helps you move things around on the screen using only code, instead of the timeline. Tweener has no idea about Papervision 3D and in fact it only changes a variable over time which means that you can change any variable as long as it is a number.
To do this you first need to set the view to interactive, then add event listeners to the 3D objects.
var controlPlane:Plane = new Plane(); controlPlane.addEventListener (InteractiveScene3DEvent.OBJECT_CLICK, plane1Clicked); controlPlane.addEventListener (InteractiveScene3DEvent.OBJECT_OVER, plane1Rollover); controlPlane.addEventListener (InteractiveScene3DEvent.OBJECT_OUT, plane1Rollout);
Then create functions and use tweener to manipulate the 3D objects
private function plane1Rollover (myEvent:InteractiveScene3DEvent):void {
//moves the panel back on roll over
Tweener.addTween(myEvent.currentTarget, { z:120, time:.5, transition:"easeInOutQuint" } );
}
private function plane1Rollout (myEvent:InteractiveScene3DEvent):void {
//moves the panel froward to its original position on roll out.
Tweener.addTween(myEvent.currentTarget, { z:100, time:.5, transition:"easeInOutQuint" } );
}
private function plane1Clicked (myEvent:InteractiveScene3DEvent):void {
//Resets the panels X rotation
myEvent.currentTarget.rotationX = 0;
//Flips the panel 360
Tweener.addTween(myEvent.currentTarget, { rotationX:360, time:1, transition:"easeInOutQuint" } );
}
Follow this link to view a demo and as usual to view the full source right click the demo.
2009-07-14
Embedding Flex Components
Ok, so before I start I have to say that the control is not actually embedded, all I managed it to do is get control as an image and apply it as a material to the plane. Click the image to the right to see the demo you can view the source by right clicking the demo.
I am working on getting the material to update when the control updates but that may be a while before it is working perfectly, as this is all I need for the project template.
2009-07-12
Reflection

The source is available if you right click the demo
2009-07-09
Using an Embedded Flex Image in Papervision3D
[Embed(source="assets/earthmap.jpg")] public var earthMap:Class; private var moonMaterial:BitmapMaterial;
Create a new BitmapAsset variable cad cast the image class to it.
var earthAsset:BitmapAsset = new earthMap() as BitmapAsset;
Finally assign the new variable as a material.
earthMaterial = new BitmapMaterial(earthAsset.bitmapData);
2009-07-08
Papervision3D
To view the source right click the movie and select view source.
2009-07-07
Project Template
I spent a week doing the flex in a week and then it was time to come up with an project to see how this flex thing really works. This is where the contest I won came into play I won $100 of templates and got this template so I figured what better way to learn flex that to try and recreate it using flex instead of boring old flex so project template was born, I will update here as I work through it with all source code included.
