| Subcribe via RSS

Accessing the contents of a folder

October 5th, 2009 | 3 Comments | Posted in AIR, ActionScript 3.0

AIR allows you to obtain a list of files and folders in a particular folder. This can be very useful if, for example, you want to create an application to load and display all images in a given folder. For each file and folder, you can also access detailed information such as the size, the extension (if it’s a file), the remaining disk room, the creation date, and so on.To access the list of files and documents in a folder, you have to use the getDirectoryListing() function provided by the File class. This method returns a list of File objects contained in the relevant folder.

In this exemple I will use a “DataGrid” to be easy to see what we have in the folder, a “TextArea” to see the location of the folder, and of course a button. Well, this is code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package 
{
	import fl.controls.Button;
	import fl.controls.DataGrid;
	import fl.controls.TextArea;
	import fl.controls.dataGridClasses.DataGridColumn;
	import fl.data.DataProvider;
 
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filesystem.File;
 
	public class Main extends MovieClip
	{
 
		public var choose:Button;
		public var output:TextArea;
		public var directoryList:DataGrid;
 
		private var folder:File;
 
		public function Main()
		{
			super();
 
			choose.addEventListener( MouseEvent.CLICK, showDirectorySelection );
 
			var col1:DataGridColumn = new DataGridColumn();
			var col2:DataGridColumn = new DataGridColumn();
			var col3:DataGridColumn = new DataGridColumn();
			var col4:DataGridColumn = new DataGridColumn();
 
			col1.headerText = "File name";
			col1.dataField = "name";
			directoryList.addColumn( col1 );
 
			col2.headerText = "File size";
			col2.dataField = "size";
			directoryList.addColumn( col2 );
 
			col3.headerText = "File extension";
			col3.dataField = "extension";
			directoryList.addColumn( col3 );
 
			col4.headerText = "Creation date";
			col4.dataField = "creationDate";
			directoryList.addColumn( col4 );
		}
 
		private function showDirectorySelection( event:MouseEvent ):void
		{
			folder = new File();
 
			folder.addEventListener( Event.SELECT, directorySelected );
			folder.browseForDirectory("Choose a directory on your system");
		}
 
		private function directorySelected( event:Event ):void
		{
 
			output.appendText("Selected folder: "+folder.nativePath+"\n");
 
			var directoryContents:Array = folder.getDirectoryListing();
			var dp:DataProvider = new DataProvider();
			var folderNum:int = -1;
			var item:File;
 
			for each( item in directoryContents )
			{
				if( item.isDirectory )
				{
					folderNum++;
					dp.addItemAt( item, folderNum );
				}
 
				else
				{
					dp.addItem( item );
				}
			}
 
		directoryList.dataProvider = dp;
		}
	} 
}

And you can download the final AIR file by here: Accessing the contents of a folder

Tags: , , , , ,

Simple 3D Carousel AS 3.0

August 14th, 2009 | No Comments | Posted in ActionScript 3.0

As the title says, this is a simple 3D Carousel AS 3.0. XML driven images, easy to implement in your Flash projects. You can buy or see the demo here: http://www.flashcomponents.net/component/simple_3d_carousel_as_3.0.html

I do not want to come up with accurate descriptions, If you like it, buy it.

Cya, next time.

Tags: , , , , , , ,

Create Cool Line Effects using Actionscript 3.0

May 19th, 2009 | 2 Comments | Posted in ActionScript 3.0, Flex

In this tutorial, you will learn the basics of architecting a simple Line Effect, using Flash CS4 or Flex Builder 3. We try to cover the basics on the simplest way, so everyone will be able to step in the scripted animation with actionscript 3.0. The fact of using only code to generate animation and effects, will result on a very small file size, which will improve the loading performance on the browser and enables a better interactivity experience.

This is description that the http://www.thetechlabs.com/ makes for this tutorial. Well, this tutorial is made by me and if you want to learn something new , have a look - Click for Tutorial-.
And the final result you can see here: Tags: , , , , , , ,

Simple Full Screen Mode

March 14th, 2009 | 1 Comment | Posted in ActionScript 3.0

A friend of mine had a problem with a Full Screen Mode, and for resolve the issue he asked me, how to make a Full Screen Mode with two buttons, The first for Full Screen Mode and the second for Normal Screen, yesterday I make this project. She’s a verry simple work, even if you are new in ActionScript, you will undersund this code. This Full Screen Mode can be make in AIR. Well, this is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package
{
	     // ----------------------------------------
        //  Imports
       // ----------------------------------------
 
	import flash.display.MovieClip;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.display.StageDisplayState;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.events.Event;
 
	public class FullScreen extends MovieClip
	{
		 // ----------------------------------------
        //   Variables
       // ----------------------------------------
 
	    //Same public variables which will help us in the following private methodes
 
		// That will be the Full Screen button
		public var fullScreen_mc:MovieClip = new MovieClip();
		// And this will be the button that will stop the Full Screen Mode
		public var stopFullScreen_mc:MovieClip = new MovieClip();
		//The text that will be displayed in the top left on the stage
		public var textLabel:TextField = new TextField();
		//The text that will be displayed when your mouse will be on top off a button
		public var toolTip:TextField = new TextField();
 
		public function FullScreen():void
		{
		  // ----------------------------------------
         //  CONSTRUCTOR
        // ---------------------------------------
 
           //Now set the constructor of your ActionScript class
 
		   //Set the stage position
		    stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.addEventListener(Event.ENTER_FRAME, checkStatus);
			drawButton(fullScreen_mc);
			drawButton(stopFullScreen_mc);
			writeText(textLabel);
			writeText(toolTip);
			//Make the toolTip invisible, because we whant to be visible wehen  will be on top off a button
			toolTip.visible = false;
			fullScreen_mc.x = 0;
			stopFullScreen_mc.y = fullScreen_mc.width + 10;
			textLabel.y = 0;
 
			//The events that will be applyed to this button
			with(fullScreen_mc)
			{
				addEventListener(MouseEvent.CLICK, putFullScreen);
				addEventListener(MouseEvent.ROLL_OVER ,rollOverMe);
				addEventListener(MouseEvent.ROLL_OUT, rollOutMe);
			}
 
			//same here...the events that will be applyed to this button
			with(stopFullScreen_mc)
			{
				addEventListener(MouseEvent.CLICK, stopFullScreen);
				addEventListener(MouseEvent.ROLL_OVER, rollOverMe);
				addEventListener(MouseEvent.ROLL_OUT, rollOutMe);
			}
		}
 
		  // ----------------------------------------
         //  Public Methods
        // ----------------------------------------
 
		public function rollOverMe(event:MouseEvent):void
		{
			toolTip.visible = true;
			switch(event.currentTarget)
			{
				case stopFullScreen_mc:
				toolTip.htmlText = "<b>End Full Screen Mode</b>";
				break;
 
				case fullScreen_mc:
				toolTip.htmlText = "<b>Full Screen Mode</b>";
				break;
			}
		}
 
		public function rollOutMe(event:MouseEvent):void
		{
			toolTip.text = "";
			toolTip.visible = false;
		}
 
		public function drawButton(obj:MovieClip):void
		{
			with(obj.graphics)
			{
				beginFill(0x666666, 1);
				drawRect(0,50,120,30);
				endFill();
			}
 
			addChild(obj);
			obj.buttonMode = true;
		}
 
		public function writeText(obj:TextField):void
		{
			obj.autoSize = "left";
			obj.border = true;
			obj.background = true;
			obj.backgroundColor = 0XFFFFFF;
			addChild(obj);
		}
		public function putFullScreen(event:MouseEvent):void
		{
			stage.displayState = StageDisplayState.FULL_SCREEN;
			textLabel.htmlText = "The application is in <b>Full Screen Mode</b>. Press the other button or press <b>ESC</b> button to escape";
		}
 
		public function stopFullScreen(event:MouseEvent):void
		{
			stage.displayState = StageDisplayState.NORMAL;
			textLabel.text = "";
		}
 
		public function checkStatus(event:Event):void
		{
			if(stage.displayState == StageDisplayState.NORMAL)
			{
				textLabel.htmlText = "The application is in <b>Normal Screen Mode</b>. Press the first button for Full Screen Mode";
			}
 
			toolTip.x = mouseX + 20;
			toolTip.y = mouseY + 20;
		}
	}
}

And the final result you can download from here :Full Screen Mode

Tags: , , , ,

Calculator

March 4th, 2009 | 1 Comment | Posted in Flex

Flex…Flex is a collection of technologies released by Adobe Systems for the development and deployment of cross-platform rich Internet applications based on the proprietary Adobe Flash platform. This is Flex, is the most powerful platform for the Flash, now many of you will say that you know to work in Adobe CS4 or CS3 Flash Professional and is enough. But I will come and say that Flash CS4 Professional is mostly for animations, not for creating applications, or developing any kind of things. For developing Flex is
the best way for the performance.
For the next post I prepared a very simple calculator, I will show you the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    frameRate="30"
    layout="absolute" viewSourceURL="srcview/index.html">
 
<mx:Script>
	<![CDATA[
 
		import mx.events.FlexEvent;
 
		/**
        * @private
        * We introduces variables that are specific to each operation
        * nr_1 is for the first number that will be introduced in the Calculator
        * nr_2 of course is for the second number
        **/
        private function calculate (event:MouseEvent):void
		{
			var nr_1:Number = Number(text_1.text);
			var nr_2:Number = Number(text_2.text);
			var amount:Number;
			var product:Number;
			var division:Number;
			var subtract:Number;
 
  		 /**
     	 * Operations corresponding to each variable
		 **/
			amount = nr_1 + nr_2;
			product = nr_1 * nr_2;
			division = nr_1 / nr_2;
			subtract = nr_1 - nr_2;
 
		/**
		* Well here we show the type of operation you want to do
		* By selecting a RadioButton
		**/ 
 
			if (plus.selected == true)
			{
				result.text = String(Math.floor(amount));
 
			}
			else if (minus.selected == true)
			{
				result.text = String(Math.floor(subtract));
			}
 
			else if(inmultire.selected == true)
			{
				result.text = String(Math.floor(product));
			}
 
			else
			{
				result.text = String(Math.floor(division));
			}
 
		}
	]]>
 
</mx:Script>
 
<mx:Panel width="400" height="300" layout="absolute"
	title="Calculator" id="panel" left="10" top="10">
 
<mx:TextInput width="70" height="20" id="text_1" x="82" y="30"/>
<mx:TextInput width="70" height="20" id="text_2" x="82" y="67"/>
<mx:TextInput x="82" y="109" width="70" height="20"/>
 
<mx:TextInput x="82" y="109" width="70" height="20" id="result"/>
 
<mx:Button label="Calculate" click="calculate(event)"  x="151" y="209"/>
	<mx:Label x="10" y="32" text="Number 1:"/>
	<mx:Label x="10" y="69" text="Number 2:"/>
	<mx:Label x="10" y="111" text="Resulte:"/>
	<mx:RadioButton x="295" y="25" label="+" id="plus"/>
	<mx:RadioButton x="295" y="50" label="-" id="minus"/>
	<mx:RadioButton x="295" y="75" label="*" id="inmultire"/>
	<mx:RadioButton x="295" y="100" label="\" id="impartire" selected="true"/>
 
</mx:Panel>
 
</mx:Application>

There is the resulte: Calculator

Tags: , , , ,
Get Adobe Flash playerPlugin by wpburn.com wordpress themes