riaxe snippets
actionscript
AS3 Transform Tool for scaling, rotating components containing text controls in Flex
Apr 23rd
Hello Everybody, Got a chance to play with the Matrix class in as3 for creating a custom transform tool for scaling and rotating components containing text controls like the TextArea in Flex. I used the free Senocular’s Transform tool available but it scales the target component using the Matrix scaling resulting in scaling the text inside the text control. So I used the Matrix class for rotating the tool and changed the width and height of the target by using transform matrix of the target.
You can find the first example here.
=============================================================
=============================================================
Find the second example here.
=============================================================

- Tranform tool v2
- Live Example can be found here
Added a simple example of rotating a button control using transform matrix with source.
You can find the demo with source here.
Hope this is useful
Advance Button creator with custom gradient and corners
Mar 17th
As we know working with graphics is real fun but it is also difficult creating complex drawable components. I had a chance to create a advance button with properties like custom gradient, custom corner change, draggable corner radius change, draggable scaling etc. Have a look.
The working example with source can be found here.
Alive PDF from Flash Player 10 issue
Mar 7th
I had an issue generating PDF from dynamic components from Flex. I used a VBox and added buttons as child dynamically. I created pages each time a child is added and at the end generated the PDF. The PDF created blank pages. I posted the issue in Kalen Gibbons’ Blog. Thanks to Kalen……the issue was solved. I would like to share the code with all of you.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" initialize="initializeHandler()">
<mx:Script>
<![CDATA[
import mx.events.CloseEvent;
import mx.controls.Alert;
import org.alivepdf.saving.Download;
import org.alivepdf.images.ResizeMode;
import org.alivepdf.saving.Method;
import org.alivepdf.images.ImageFormat;
import org.alivepdf.pages.Page;
import org.alivepdf.display.*;
import org.alivepdf.layout.*
import org.alivepdf.pdf.PDF;
private var mPDF:PDF;
private var numChildrenToAdd:Number = 10;
private function initializeHandler():void{
//initialize PDF
mPDF = new PDF(Orientation.PORTRAIT, Unit.MM, Size.A4 );
mPDF.setDisplayMode( Display.FULL_PAGE, Layout.SINGLE_PAGE );
}
private function onPDFCreate():void
{
/* Kick off a loop of adding children to the vbox.
When the child is added, the updateComplete handler will add
a page to the PDF and add another button to the vbox, which will
trigger the updateComplete handler and start the loop over again...
until all children have been added. */
var btn:Button = new Button();
btn.label = 'Click 1';
vbox.addChild(btn);
}
private function updateHandler():void{
//get the current number of children
var currentChildren:int = vbox.numChildren;
if(currentChildren == 0){ return; }
//add new page
var newPage:Page = new Page( Orientation.PORTRAIT, Unit.MM, Size.A4 );
mPDF.addPage( newPage );
mPDF.addImage(vbox, 0, 0, 0, 0, ImageFormat.PNG, 100, 1 );
//keep the loop going until all children have been addded
if(currentChildren < numChildrenToAdd){
var btn:Button = new Button();
btn.label = 'Click '+ (currentChildren+1);
vbox.addChild(btn);
}else if(currentChildren == numChildrenToAdd){
//all children are added so it's okay to print now
//mPDF.save(Method.REMOTE, "http://kalengibbons.com/assets/pages/pdfCreator.cfm", Download.INLINE);
Alert.show('Do u wanna pdf?', 'PDF Creation', Alert.OK|Alert.CANCEL, this, alertListener, null, Alert.OK);
}
}
private function alertListener(vEvent:CloseEvent):void
{
if(vEvent.detail == Alert.OK){
var file:FileReference = new FileReference();
file.save(mPDF.save(Method.LOCAL), "Module.pdf.pdf");
}
}
]]>
</mx:Script>
<mx:VBox id="vbox" borderStyle="solid" borderColor="0xff00ff"
width="100%" height="100%" updateComplete="updateHandler()" />
<mx:Button id="btn" label="CreatePDF" click="onPDFCreate()"/>
</mx:Application>
Dynamic TextArea control that resizes with the text content
Feb 6th
I found myself quite helpless creating a custom TextArea control resize itself with the text content. I followed the docs, help, googled the web to find something called textHeight and textWidth properties of the TextArea but that was not enough because it doesn’t resize itself on initialisation according to the text available within itself. For resizing the text on initialisation, the text should be validated. I tried validateNow() for validating the text but that too didn’t work. For making it work I created a custom TextArea component in mxml with a StringValidator. I have also added the text formatting part from keyboard shortcuts into the code using a TextRange.
The working example for this can be found here.
Here’s the code for the above example:
<?xml version="1.0" encoding="utf-8"?>
<mx:TextArea xmlns:mx="http://www.adobe.com/2006/mxml"
htmlText="Welcome to Flex3.0" wordWrap="false" change="onValidation()"
verticalScrollPolicy="off" horizontalScrollPolicy="off"
height="22" width="108" creationComplete="init()"
keyDown="onKeyDown(event)" updateComplete="onValidation()">
<mx:Script>
<![CDATA[
import mx.controls.textClasses.TextRange;
private function init():void
{
this.validateNow();
}
private function onValidation():void
{
var metrics:TextLineMetrics = this.getLineMetrics(0);
this.width = this.textWidth + 10;
this.height = this.textHeight + 10;
this.verticalScrollPosition = 0;
this.horizontalScrollPosition = 0;
}
private function onKeyDown(e:KeyboardEvent):void
{
var tr:TextRange = new TextRange(this, true);
if(e.ctrlKey && e.keyCode == 66){
if(tr.fontWeight == "normal"){
tr.fontWeight = "bold";
}
else{ tr.fontWeight = "normal" }
}
if(e.ctrlKey && e.keyCode == 73){
if(tr.fontStyle == "normal"){
tr.fontStyle = "italic";
}
else{ tr.fontStyle = "normal" }
}
if(e.ctrlKey && e.keyCode == 85){
if(tr.textDecoration == "normal"){
tr.textDecoration = "underline";
}
else{ tr.textDecoration = "normal" }
}
}
]]>
</mx:Script>
<mx:StringValidator source="{this}" property="text"
minLength="10" valid="onValidation()"/>
</mx:TextArea>






