| 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: , , , , ,

Animation Window

February 26th, 2009 | 2 Comments | Posted in AIR, ActionScript 3.0

Well, this is another AIR project with Native Window. In this AIR project you will see how to animate a Native Window, and the Tween Method if you do not already know, but I think you are knowing this method. I used the simple Tween Method not the TweenMax or another. But if you like the TweenMax you can use it. The code is not very hard to understand. Put if you don’t understand go to the previous post and look there or leave me a comment, and I will answer you in the shortest time.
OK…enough talking, this is the code and the explanations:

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
package
{
	     // ----------------------------------------
        //  Imports
       // ----------------------------------------
 
	import flash.display.MovieClip;
	import flash.display.NativeWindow;
	import flash.display.NativeWindowType;
	import flash.display.NativeWindowInitOptions;
	import flash.display.NativeWindowSystemChrome;
	import flash.display.StageDisplayState;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.text.TextField;
	import flash.events.MouseEvent;
	import flash.system.Capabilities;
	import fl.transitions.Tween;
	import fl.transitions.easing.Bounce;
	import fl.transitions.TweenEvent;
 
	public class AnimationWindow extends MovieClip
	{
		 // ----------------------------------------
        //   Variables
       // ----------------------------------------
 
	    //Same public variables which will help us in the following private methodes
		public var mainWindow:NativeWindow;
		public var newWinInit:NativeWindowInitOptions = new NativeWindowInitOptions ();
		public var newWin:NativeWindow;
		public var labelText:TextField = new TextField();
		public var createIt:MovieClip = new MovieClip();
		public var moveWin:MovieClip = new MovieClip();
		public var thisTime:Date = new Date();
 
		  // ----------------------------------------
         //  CONSTRUCTOR
        // ---------------------------------------
           //Now set the constructor of your ActionScript class
		public function AnimationWindow ():void
		{
			//At this point, you must remember that the new window you will create has to keep the
            //content unaltered. To do this, you have assigned the StageScaleMode.NO_SCALE value to scaleMode
            //property and the StageAlign.TOP_LEFT value to the  align properties
			mainWindow = stage.nativeWindow;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
 
			//The content for the New Native Window
			labelText.htmlText = String("Today is <b>"+thisTime.getDate()+"/"+(thisTime.getMonth()+1)+"/"+thisTime.getFullYear()+"</br>");
 
			addChild(createIt);
			addChild(moveWin);
			designButton(createIt, 100,30,0,0);
			designButton(moveWin, 100,30,0,100);
 
			createIt.addEventListener(MouseEvent.CLICK,createWindow);
			moveWin.addEventListener(MouseEvent.CLICK, moveWindow);
		}
		  // ----------------------------------------
         //  Private Methods
        // ----------------------------------------
 
		private function createWindow(e:MouseEvent):void
		{
			//Next are the methods that create the new window:
			newWinInit.systemChrome = NativeWindowSystemChrome.STANDARD;
			newWinInit.type = NativeWindowType.UTILITY;
			newWin = new NativeWindow(newWinInit);
			newWin.activate()
			newWin.stage.addChild(labelText);
			newWin.title = "Calendar|Window";
			newWin.x = 0;
			newWin.width = 300;
			newWin.height = 100;
			newWin.stage.addEventListener(MouseEvent.CLICK,closeMe);
		}
 
		function closeMe(event:MouseEvent):void
		{
			//The closeMe method allows you to close both of the windows once the user clicks the utility window.
			newWin.close();
			mainWindow.close();
		}
 
		private function moveWindow(event:MouseEvent)
		{
			//The next method, allows you to move the window on the user’s desktop.
			var moveIt:Tween = new Tween(newWin, "x", Bounce.easeOut,newWin.x,((Capabilities.screenResolutionX) - newWin.width), 5, true);
 
			moveIt.addEventListener(TweenEvent.MOTION_FINISH,backIt);
			function backIt(event:TweenEvent)
			{
				moveIt.yoyo();
			}
		}
 
		private function designButton(obj:MovieClip, objWidth:Number, objHeight:Number, objX:Number, objY:Number)
		{
			//Set the position to the buttons
			with(obj.graphics)
			{
				beginFill(0xAACCDD, 1);
				drawRect(objX,objY,objWidth, objHeight);
				endFill()
			}
			obj.buttonMode = true;
		}
	}
}

There is the file with .air extension: Animation Window

Tags: , , , ,

Native Window

February 24th, 2009 | 3 Comments | Posted in AIR, ActionScript 3.0

I apologize for my absence, but I have same problems. Well today I make something very easy and basic for a AIR aplication. The aplication had to be ready yesterday, put the develop platform makes me same troubles. The aplication name is Native Window, well this aplication prcatic will open a new window inside the first. Here 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
package
{
	     // ----------------------------------------
        //  Imports
       // ----------------------------------------
 
     //Import the MovieClip-- for the Constructor and for the button
	import flash.display.MovieClip;
	//Import the NativeWidow  of course for the New Native WIndow that will be created
	import flash.display.NativeWindow;
	//Import the MouseEvent for the button Mouse Click
	import flash.events.MouseEvent;
	/*And finaly will import the NativeWindowInitOptions 
	fot the future options that will be applied on the NativeWindow*/
	import flash.display.NativeWindowInitOptions;
 
	public class main extends MovieClip
	{
		 // ----------------------------------------
        //   Variables
       // ----------------------------------------
 
		  //Same private variables which will help us in the following private methodes
		//The newWin represents the NativeWindow
		public var newWin:NativeWindow;
		//This represents the button that will open the NativeWindow
		public var myButton:MovieClip = new MovieClip();
		//And this are the Native Window Option
		public var init:NativeWindowInitOptions = new NativeWindowInitOptions();
 
		public function main():void
		{
		  // ----------------------------------------
         //  CONSTRUCTOR
        // ---------------------------------------
 
			// I set the resizable option "true"
			init.resizable = true;
			//I set the maximizable option  "false"
			init.maximizable = false;
			//And the minimizable option "true"
			init.minimizable = true;
			//Init the drawButton function, which will be described later
			drawButton(myButton);
			myButton.addEventListener(MouseEvent.CLICK, openWindow);
		}
		  // ----------------------------------------
         //  Private Methods
        // ----------------------------------------
 
		private function drawButton(obj:MovieClip):void
		{
			with(obj.graphics)
			{
				// Draw the rect for the button
				beginFill(0xAAEECC, 1);//Set the Color and the Alpha
				drawRect(10,10,100,20);//Set the position
				endFill();
			}
			addChild(obj);
			obj.buttonMode = true; //Give the buttonMode to the obj
		}
 
		  // ----------------------------------------
         //  Private Methods
        // ----------------------------------------
 
		private function openWindow(e:MouseEvent):void
		{
			newWin = new NativeWindow(init); //Initialize the Native Window
            newWin.activate(); //Activate the Window
			//Set the position
			newWin.height = 200;
			newWin.width = 300;
			//Give a name
			newWin.title = "My First New Win!";
		}
	}
}

I hope you like it. There is the file with .air extension: Native Window

Tags: , , ,

Simple Web Browser

February 14th, 2009 | No Comments | Posted in AIR, ActionScript 3.0

Well, this is a new categorie in my blog, her name is AIR, this Adobe AIR is a cross-platform runtime environment for building rich Internet applications using Adobe Flash, Adobe Flex, HTML, or Ajax, that can be deployed as a desktop application. This first project is a Web Browser, a very simple Web Browser

Here is the code and the comments:

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
package
{
	     // ----------------------------------------
        //  Imports
       // ----------------------------------------
 
	import flash.display.Sprite;
	import flash.html.HTMLLoader;
	import flash.net.URLRequest;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.KeyboardEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
 
	public class MyHTML extends Sprite
	{
		 // ----------------------------------------
        //   Variables
       // ----------------------------------------
	      //Same private variables which will help us in the following private methodes
 
		public var urlReq:URLRequest = new URLRequest("http://www.google.com");
		public var myHTML:HTMLLoader = new HTMLLoader();
		public var address_txt:TextField = new TextField();
		public var address_btn:Sprite = new Sprite();
		public var addressLabel_txt:TextField = new TextField();
 
		  // ----------------------------------------
         //  CONSTRUCTOR
        // ---------------------------------------
 
		public function MyHTML()
		{
 
			myHTML.width = stage.stageWidth; //Set the myHTML width
			myHTML.height = stage.stageHeight - address_txt.y; //Set the myHTML
			myHTML.load(urlReq); //Load the first page in the browser
 
			with(address_txt)
			//Set the address_txt option
			{
				border = true;
				type = TextFieldType.INPUT; // The tipe of the address_txt must be Input
				x = 18; //Set the x
				y = 5; //Set the y
				width = 360; //Set the width
				height = 22; //Set the height
				text = "http://www.google.com"; // This is the text how is in the address_txt
				background = true;
				backgroundColor = 0xFFFFFF; //Set the color
			}
 
			with(address_btn)
			// Draw the rect for the button
			{
				graphics.beginFill(0xFFFFFF, 1); //Ste the Color and the Alpha
				graphics.drawRect(400,5,50,20); // Set the x, the y and the position of the rect
				graphics.endFill();
				buttonMode = true; //Set the button Mode
			}
 
			with(addressLabel_txt)
			{
				x = 400;
				y = 5;
				text = "GO!"
				autoSize = TextFieldAutoSize.LEFT;
				selectable = false;
				mouseEnabled = false;
			}
 
			//Add to the stage: myHTML, address_txt, address_btn and addressLabel_txt
			addChild(myHTML);
			addChild(address_txt);
			addChild(address_btn);
			addChild(addressLabel_txt);
			//Set the myHTML position
			myHTML.x = 0;
			myHTML.y = this.address_txt.y + this.address_txt.height + 5;
			address_btn.addEventListener(MouseEvent.CLICK, viewPageHandler);
			stage.addEventListener(KeyboardEvent.KEY_DOWN, viewPageHandlerByEnter);
		}
 
		  // ----------------------------------------
         //  Private Methods
        // ----------------------------------------
 
		private function viewPageHandler(event:MouseEvent)
		//This load the URL and transform to a page content
		{
			urlReq = new URLRequest(address_txt.text);
			myHTML.load(urlReq);
		}
 
		private function viewPageHandlerByEnter(event:KeyboardEvent)
		//Well this make the same thing but if you press Enter
		{
			if(event.keyCode == 13)
			{
				urlReq = new URLRequest(address_txt.text);
				myHTML.load(urlReq);
			}
		}
	}
}
 
//Remember this is Air not Flash, the HTMLLoader not work in a flash project.

Well this is a very simple Web Browser. And I say again this is a Air project , not a Flash project, and the HTMLLoader not works on a Flash project
Here is the result:Web Browser

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