How to Print contents of a Container (Canvas) ?

July 3, 2008

Here iam having two Two containers (canvas) with my data in it and now I want to print the contents of the canvas as a whole.

Two containers [canvas] à PrintPreviewL,PrintPreviewR
Now I want to print the contents of these containers.

The function which does the print is :

public function doPrint():void
{
// Create a FlexPrintJob instance.
var printJob:FlexPrintJob = new FlexPrintJob();

// Start the print job.
if(printJob.start()) {
// Create a PrintView control as a child
// of the current view.
var formPrintViewL:PrintPreviewL = new PrintPreviewL ();
var formPrintViewR: PrintPreviewR = new PrintPreviewR();
addChild(formPrintViewL);
addChild(formPrintViewR);
// Add the SimplePrintview control to the print job.
// For comparison, try setting the
// second parameter to “none”.
printJob.addObject(formPrintViewL);
printJob.addObject(formPrintViewR);
// Send the job to the printer.
printJob.send();

// Remove the print-specific control to free memory.
removeChild(formPrintView);
removeChild(formPrintViewT);
}

}

This will print the contents of the two canvas in sequence as we send to the printJob.As you can see.

Can go through the classes to learn the Basics and start. All the Best.

Enjoy the code ! :-), leave me comments for queries.


Using NumberFormatter !

July 2, 2008

This class is used to format the number in a way we like, like the number 2000 to 2,000 or 2000 to 2,00.00 or 2000.2345 to 2,000.23 like that.So the usage is given below, its like the beautification to the data.

Code Example:

<mx:NumberFormattter id=”nftr” precision=”2″ />

Now in a the Script block u can use this to format the number.As

nftr.format(2000.123456);

This will format to 2,000.12.

There are still many properties in the NumberFormatter class to use like thousandSeperatorfrom,thousandSeperatorto …… like so, can explore these very simple.

As i said it addds beautification to the data in the Application.

Enjoy the post.Can leave a comment for queries.


Conditional Operator.

June 30, 2008

The syntax in Flex for conditional operator is same as that of the other technologies like c,java,.., for newbies the syntax is here.

Syntax:

Condition?(condition=true)statement:condition=false)statement.

Or

Condition?true satement:false statement.

It is nothing but a if.. else.. block in one single line.

Example in Flex:

Private function conopeExample():void

{

txtname.text=4>1?”Kumar”:”gandhi”;

}

<mx:TextInput id=”txtname” />

<mx:Button id=”btn” click=” conopeExample” />

The conditional operator is so simple that we programmers ignore that , or not interested in that. But it’s so simple that a good programmer will use to reduce the lines of code in the Application. Finally it’s synonym of our if .. else .. statements.

Enjoy the Post.


Reading data in to ComboBox from PHP page. (corrections)

June 21, 2008

Actually I made this post long back but the post had some corrections so iam making those here. It was actually suggested by a a person called John that he didn’t get the post clearly and insisted to make another one for newbies. So I decided to make a clear one here with complete code.

The post missed one line as it was pointed out in the comment , the line is to send the HttpService you are using to get the Data.

Flex code :

<?xml version=”1.0″ encoding=”utf-8″?>

<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute

creationComplete=”projectsSrv.send();”>

<mx:HTTPService

id=”projectsSrv

url=”new.xml

useProxy=”false” method=”POST>

</mx:HTTPService>

<mx:ComboBox

id=”cmb1” x=”152” y=”53

dataProvider=”{projectsSrv.lastResult.records.record}

labelField=”data></mx:ComboBox>

</mx:Application>

PHP code or XML file code:

<records>

<record data=”1″ label=”Corco”/>

<record data=”5″ label=”Shell Crop Protection”/>

<record data=”7″ label=”Olin McIntosh”/>

<record data=”9″ label=”Crab Orchard”/>

<record data=”10″ label=”Shell Oil Del Amo”/>

<record data=”11″ label=”AIG South Jersey Gas”/>

<record data=”12″ label=”Husch &amp; Eppenberger Litigation-New York”/>

<record data=”22″ label=”Shell Sturbridge”/><record data=”24″ label=”Shell Southington”/>

<record data=”26″ label=”Olin Personal Injury”/>

</records>

You can send data in this format or get it from the XML file, here its from XML file “new.xml”.you can even echo these lines in PHP and a file as new.php.

As you can see the difference here, from that post is, here iam using the line creationComplete=”projectsSrv.send();” in the Application tag to send the service and read the data.

Now it will work fine and comments are welcome !


Giving title to your Flex App’s.

June 17, 2008

Usually we give title to our page from the Title Tag in the Html file but there is another way to do this from the Flex App.

There’s a property called pageTitle in the Application Tag, and there you can mention it. Then it appears on Browser Title Bar as required. Cool isn’t it !

Code Example :

<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute”

creationComplete=”init()” pageTitle=”Kumar Gandhi Page !”>

</mx:Application>

Enjoy the code !


Incremental compilation in Flex.

June 4, 2008

I collected some information in Incremental Compilation and iam giving it here.

Incremental compilation means that the compiler inspects your code, determines which parts of the application are affected by your changes, and only recompiles the newer classes and assets (section of bytecode). These sections of bytecode are also referred to as compilation units.

Incremental compilation can help reduce compile time on small applications, but you achieve the biggest gains on larger applications. The default value of the incremental compiler option is true for the Flex Builder application compiler. For the mxmlc command-line compiler, the default is false.

You enable incremental compilation by setting the incremental option to true, as the following example shows: mxmlc -incremental=true MyApp.mxml

As part of the incremental compilation process, the compiler generates
a cache file that lists the compilation units of your application and information on your
application’s structure. This file is located in the same directory as the file that you are
compiling. For example, if my application is called Example.mxml, the cache file is called Example_n.cache, where n represents a checksum generated by the compiler based on compiler configuration. This file helps the compiler determine which parts of your application must be recompiled. One way to force a complete recompile is to delete the cache file from the
directory.

Hope you got the importance of it !.Enjoy the Post.


New DateField Component with the BackgroundColor Property. Explanation

May 27, 2008

This post is continuation of the previous post.

How to do this:

Create a lib project with a new Class which extends the DateField Class and the required .swc file is created in the bin folder.

Now we need to include one .as file which defines all the required properties for the DateField Component.

The .as file is already available for the TextInput component, which defines the required border properties. So all we need to do is get that file and include it in the NewDateFiled Class.

The .as file is BorderStyles.as and it is present in the sdk’s at

C:\Program Files\flex_sdk\frameworks\projects\framework\src\mx\styles\metadata

Now get this .swc file generated [lib] into the your projects [paste it in your projects lib folder ] and drag the NewDateField component from the custom folder from the design view.

Now you can see the new properties included in the NewDateField component.

The below image shows the New DateField component with BackgroundColor property.

Enjoy the post ! comments are welcome for queries ..


New DateField Component with the BackgroundColor Property.

May 22, 2008

It may be thought by the Developers who did the DateField component that BackgroundColor property may not be required, or I don’t know their intention , but what if it is required for your App ?.

Even we [our projects] had this requirement in the beginning, when we were into projects, but I could not find time to do R&D. After I got in to the core part of the Framework and explored the classes and got the logic to implement this.

To tell frankly its simple but to get the logic you really need to explore the classes.

newdate

Will come back with explantion. The above image shows the NewDateField Component.


ActionScript Execution TimeLimit !

May 15, 2008

The default time for executing .as[ Script ] file is 15 sec’s and if the the file takes more that 15 sec’s it throws an Runtime Exception Error #:1502, and the below image shows the error message.

Here if we wanted our Script to execute more than the default time then we need to specify the time limit at the Application [Tag].

The property to use is :

scriptTimeLimit

It takes the value for sec’s specification. And the max value it can have is 60 sec. It means that the Script can be executed for only 60 sec’s.

Code Example:

<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” creationComplete=”init()” scriptTimeLimit=”40>

</mx:Application>

The below image shows the Error Message:

Error Message For Script TimeOut .!

Enjoy The code..!


Designing BusyCursor’s or Custom BusyCursor’s.

May 8, 2008

There is default skin for BusyCursor and that skin is in the pakage mx.skins and .as file BusyCursor you can find them in your sdk’s

Now coming to desing BusyCursor:

Here we need to design our own Cursor Programmatically that is write a class which extends the Sprite Class  and use the Graphics class and with its methods, you can make your own Design for Cursor’r and finally include the skin in the App as a Style, with the Property busyCursor in the CursorManager Class.

<mx:Style>

CursorManager {

busyCursor: ClassReference(”NewBusyCursorSkin”);

}

Here NewBusyCursorSkin is the class which draws your skin[ contains code to draw] and include that class as below.And when including styles Programmatically we got use the ClassReference() method with the Class Name as the parameter.Above line shows it. To understand this post you need to know what is Sprite and Graphics Classes.

This image shows the Custom BusyCursor i have developed.

Custom BusyCursor.

Enjoy the Post. Stay tuned for the code.


Action Script Access time Exceeds 15 sec’s Error.

May 3, 2008

The default time for script acces is 15 sec’s and if you intend to have more access to the script then we got to use the property scriptLimittime at the Application tag.

The max value is 60 sec’s.

I will come back with Error Message and code Example.


Lock columns and Rows in DataGrid for Visibility.

April 22, 2008

There are two properties in DataGrid where we can lock the visibility of the rows and columns in the DataGrid [here lock the visibility means, which are always visible ,like when scrolling they are not moved to and forth].

The property for ColumnLock is

lockedColumnCount

this takes the value to lock the number of Columns in the Display from left of DataGrid. Here horizontalscrolling locks the columns for visibility.

The property for RowLock is

lockedRowCount

this also takes the value to lock the number of rows in the Display from top of DataGrid. Here verticalscrolling locks the rows for visibility.

code Example:

<mx:DataGrid x=”277″ y=”331″ id=”dg” dataProvider=”{xml}”

lockedColumnCount=”3″ height=”96″ horizontalScrollPolicy=”on”

verticalScrollPolicy=”on” width=”397″>

<mx:columns>

<mx:DataGridColumn headerText=”Sl.No” dataField=”slno”/>

<mx:DataGridColumn headerText=”Product Name” dataField=”PNAME”/>

<mx:DataGridColumn headerText=”Pro ID” dataField=”PID”/>

<mx:DataGridColumn headerText=”Cat ID” dataField=”CAT_ID”/>

<mx:DataGridColumn headerText=”Cat Name” dataField=”CATEGORY”/>

</mx:columns>

</mx:DataGrid>

The below image shows the locking of two columns.

Enjoy the code !, happy Flexing.


Error Message when the required dll file [plugin] is missing.

April 10, 2008

Previous post tells about the plugins requirement and i forgot to mention in that post that
the dll file is neccesary only when running the apps from Flex Builder 2 but not in Flex Builder 3.

The Erro Message displayed while running your App’s from Flex Builder 2 when the required .dll [plugin]
is missing is:
Error Message For dll file [plugin]
The above Window defines the Error.
Enjoy Flexing !


.dll file required to run the .swf file in the browser [plugin file]

April 9, 2008

Each time we run the Flex App’s the browser looks for the flash plugin in the Browser’s plugin folder.So the plugin file that is required is npswf32.dll.

This is by default included in the plugin folder of the browsers installation folder, when you install the flash player, but there is a situation  where this file  missed out sometimes when we go for Browser ’s new installs .

so at that time the file[plugin] we required [present at the folder "C:\WINNT\system32\Macromed\Flash"] is missing and need to be put it in the plugin folder of the browser install folder.

Now take the required file[copy it from the path given above] and paste it in the folder plugin folder of the browser install folder.

Now it works file.Enjoy Flexing.


About the Flex memory usage.

April 5, 2008

In the flexbuilder install folder look for flexbuilder.ini … open it in a
text editor you can change the max and min values of RAM that FlexBuilder is
allowed to use.
Although its normal fro flex builder 2 to take up that kind of resources.
They improved that a lot if Flex Builder 3