środa, 28 października 2009

Add flex content in AIR to NativeWindow without using mx:Window

The core to do that is WindowedSystemManager class and it's implementation in our TestWindow.as class.
Have a look how the class is initialized in createChildren() method. The main container here is Canvas but can be anything I think even single button or label I think (didn't tested out but feel free to check).

package
{
import flash.display.NativeWindow;
import flash.display.NativeWindowInitOptions;
import flash.events.Event;

import mx.containers.Canvas;
import mx.events.FlexEvent;
import mx.managers.WindowedSystemManager;

[Event(name="creationComplete", type="mx.events.FlexEvent")]

public class TestWindow extends NativeWindow
{
private var systemManager:WindowedSystemManager;

private var windowFlexContainer:Canvas;

private var childrenCreated:Boolean = false;

public function TestWindow(initOptions:NativeWindowInitOptions = null)
{
var options:NativeWindowInitOptions;
initOptions == null ? options = new NativeWindowInitOptions() : options = initOptions;

super(options);

addEventListener(Event.ACTIVATE, windowActivateHandler);
}

private function windowActivateHandler(event:Event):void {
event.preventDefault();
event.stopImmediatePropagation();
removeEventListener(Event.ACTIVATE, windowActivateHandler);
if(stage) {
createChildren();
stage.addEventListener(Event.RESIZE, windowResizeHandler);
}
}

private function createChildren():void {
if(!windowFlexContainer) {
windowFlexContainer = new Canvas();
}

if(!systemManager) {
systemManager = new WindowedSystemManager(windowFlexContainer);
}

stage.addChild(systemManager);

windowFlexContainer.width = stage.stageWidth;
windowFlexContainer.height = stage.stageHeight;

stage.addChild(windowFlexContainer);

childrenCreated = true;

dispatchEvent(new FlexEvent(FlexEvent.CREATION_COMPLETE));
}

private function windowResizeHandler(event:Event):void {
windowFlexContainer.width = stage.stageWidth;
windowFlexContainer.height = stage.stageHeight;
}

public function get container():Canvas {
return windowFlexContainer;
}

public function destroy():void {
removeEventListener(Event.RESIZE, windowResizeHandler);
windowFlexContainer.removeAllChildren();
stage.removeChild(windowFlexContainer);
stage.removeChild(systemManager);
windowFlexContainer = null;
systemManager = null;
}
}
}

This is fast typed so there is no way now to fully support flex-mxml work flow and to have children automatically added in code. Maybe I will extend it later to fully support adding mxml content. So now we simply create our TestWindow in mxml and add children manually when component is created.


creationComplete="testwindow2_creationCompleteHandler(event)">

import mx.events.FlexEvent;

protected function testwindow2_creationCompleteHandler(event:FlexEvent):void
{
container.addChild(label);
}

]]>




Well this is basic. And unlike mx:Window our component is not extending UIComponent but it's extending NativeWindow.
To run this component we create simple application with button great job doing button:




import flash.events.MouseEvent;

protected function button1_clickHandler(event:MouseEvent):void
{
var w:Test = new Test();
w.activate()
}

]]>




As you can see when you compile those three classes It's working :)
Peace.

środa, 16 września 2009

Easter calculation using Meeus/Jones/Butcher algorithm in as3

Well it will be short - for Gregorian calendar it will be:

public static function resolveEasterDate(year:Number):Date {
var a:Number, b:Number, c:Number,
d:Number, e:Number, f:Number, g:Number,
h:Number, i:Number, k:Number,
l:Number, m:Number, p:Number;
a = year % 19;
b = int(year / 100);
c = year % 100;
d = int(b / 4);
e = b % 4;
f = int((b+8)/25);
g = int((b-f+1)/3);
h = (19*a+b-d-g+15) % 30;
i = int(c / 4);
k = c % 4;
l = (32+(2*e)+(2*i)-h-k) % 7;
m = int((a+(11*h)+(22*l))/451);
p = (h+l-(7*m)+114) % 31;
return new Date(year,int((h+l-(7*m)+114)/31)-1, p+1 );
}

wtorek, 18 sierpnia 2009

Adobe AIR and Flex SDK dirty secrets part 1

Well there was a while since Adobe put their AIR(Adobe Integrated Runtime) to the public. The newest one is AIR 1.5.2 so there was 1.5.1, 1.5, 1.1 and 1.0 version. Adobe AIR 1.0 was released something like year ago and there are already 5 versions of this runtime each got some bug fixed.
All you should see here in release notes:
http://www.adobe.com/support/documentation/en/air/releasenotes.html
I unfortunately can't. This is only blank page for me for each version but not the last one.

So shortly, we get installer languages support in AIR, it supports 3 platforms Windows, Mac OS X and Linux.

The installer looks different and there are some more, less important enhancements like ex. check disk space available, or check transparency support.

Well when AIR was released the special flex sdk components get released too for programmers to make their life easier.

O RLY ?

I don't want to blame anybody and talk that air is bad , or the flex sdk code is sloppy. I'm also not the best programmer in the world. But since I use adobe technology I want to share what is bad and what is good for me and what you are dealing with while working with that technology.

Well Adobe want to release Flex SDK 4 but I got one fresh on my drive directly form svn and as far as I know nothing has changed what I'm writing about. That's public beta so don't wait for that changes I will make here for you.

The posts will be specially for You, that want to make glamurous applications and don't want to tear one's hair out.

Something easy for the start then:
mx.core.WindowedApplication have got showFlexChrome parameter that can be true or false. It's important for not with system chrome fancy applications.

Flexbuilder shows that this param it's style property so you can set it in style sheet. Well not exactly since it's not obvious how to use that style and since it's buggy one.

The positive part of the story is that Flex SDK is some kind of open source now so you can view the WindowedApplication component source, Thank You Adobe we need fix some stuff ;)

Let's back to the code.

Well we need to find showFlexChrome param. The first one is at 1768 line (WTF?) in createChildren() method. We are some kind of experienced Flex SDK users so we know what the method do cause we can do AS3 custom component's. It's obvious one that's creating all children of the component based on parameters you pass. so there is code:

/**
* @private
*/
override protected function createChildren():void
{
super.createChildren();

if (getStyle("showFlexChrome") == false ||
getStyle("showFlexChrome") == "false")
{
setStyle("borderStyle", "none");
setStyle("backgroundAlpha", 0);
return;
}

if (!_statusBar)
{
_statusBar = statusBarFactory.newInstance();
_statusBar.styleName = new StyleProxy(this, statusBarStyleFilters);
rawChildren.addChild(DisplayObject(_statusBar));
showStatusBarChanged = true;
}

if (systemManager.stage.nativeWindow.systemChrome != "none")
{
setStyle("borderStyle", "none");
return;
}

if (!_titleBar)
{
_titleBar = titleBarFactory.newInstance();
_titleBar.styleName = new StyleProxy(this, titleBarStyleFilters);
rawChildren.addChild(DisplayObject(titleBar));
showTitleBarChanged = true;
titleBarFactoryChanged = false;
}

if (!gripper)
{
gripper = new Button();
var gripSkin:String = getStyle("gripperStyleName");
if (gripSkin)
{
var tmp:CSSStyleDeclaration =
StyleManager.getStyleDeclaration("." + gripSkin);
gripper.styleName = gripSkin;
}
rawChildren.addChild(gripper);

gripperHit = new Sprite();
gripperHit.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
rawChildren.addChild(gripperHit);
}
}

Let's save the whole class in our project first to make sure the changes will take part.

Well just make structure mx.core, make class WindowedApplication.as, copy all source to it and also copy Version.as source to our mx/core structure and that's it we now got custom WindowedApplication but get back to main part for a second and we got 3 options how to set our style:
1. in component tag - it's working





2. in component in style tag - it's working again




WindowedApplication {
showFlexChrome: false;
}



3. in external style main.css - it's working again wow







/* CSS file */
WindowedApplication {
showFlexChrome: false;
}



So what's about ? Well let's do something like set showFlexChrome=false and then by calling setStyle() set it true. Also set our background color to red.


applicationComplete="appCompleteHandler()">

WindowedApplication {
showFlexChrome: false;
background-color: #ff0000;
}


private function appCompleteHandler():void {
setStyle('showFlexChrome', 'true');
}
]]>



It's not working now, the background is not red, why ?
That's why http://bugs.adobe.com/jira/browse/SDK-11107
Cause of the createChildren() method. There is a condition:

if (getStyle("showFlexChrome") == false ||
getStyle("showFlexChrome") == "false")
{
setStyle("borderStyle", "none");
setStyle("backgroundAlpha", 0);
return;
}

and that sets our backgroundAlpha to 0. If we set our showFlexChrome to false the background will not be showed cause alpha is 0. Wtf and why somebody is deciding for us? Also somebody decided that the borders style now will be none.
Well... the best part is third line return;
The children won't be created so the flex chrome will never be showed.


I don't really know why the showFlexChrome style is existing and why it's not a simple method cause we can loose the chrome just by doing this:


applicationComplete="appCompleteHandler()">

WindowedApplication {
background-color: #ff0000;
}


private function appCompleteHandler():void {
showGripper = showStatusBar = showTitleBar = false;
}
]]>



So it could be simple a getter / setter in WindowedApplication and it will be much simple for us.

//----------------------------------
// showFlexChrome
//----------------------------------

public function set showFlexChrome(value:Boolean):void {
showGripper = showStatusBar = showTitleBar = value;
}

public function get showFlexChrome():Boolean {
return _showGripper && _showStatusBar && _showTitleBar;
}

Let's make it in WindowedApplication.as - remove all showFlexChrome style, make some modifications to keep the code clear and what ? It's working as expected and now you can make some demo like this:


applicationComplete="appCompleteHandler()">

WindowedApplication {
background-color: #ff0000;
}


import flash.utils.setInterval;

private function appCompleteHandler():void {
setInterval(changeChrome, 2000);
}

private function changeChrome():void {
showFlexChrome = !showFlexChrome;
}
]]>



or more practical like this:


applicationComplete="appCompleteHandler()"
showFlexChrome="false">

WindowedApplication {
background-color: #ff0000;
}


import flash.utils.setTimeout;
import flash.utils.setInterval;

private var _mouseIsOver:Boolean;

private function appCompleteHandler():void {
addEventListener(MouseEvent.MOUSE_OVER, mouseRollOverHandler);
addEventListener(MouseEvent.MOUSE_OUT, mouseRollOutHandler);
}

private function mouseRollOverHandler(event:Event):void {
_mouseIsOver = showFlexChrome = true;
}

private function mouseRollOutHandler(event:Event):void {
setTimeout(hideFlexChrome, 1000);
_mouseIsOver = false;
}

private function hideFlexChrome():void {
showFlexChrome = _mouseIsOver;
}
]]>




happy codding

download sample with mx.core.WindowedApplication modifications

środa, 5 sierpnia 2009

namespace stuff for flex and as3

Well namespace here namespace there. Let me see what is that namespace in as3 ?

If you were ever programming flex framework you already have used it!

I'll try to show you the whole magic:


xmlns:mx="http://www.adobe.com/2006/mxml"

That's it.

layout="absolute"
minWidth="1024"
minHeight="768">



The namespace is "http://www.adobe.com/2006/mxml" and the namespace accessor is simply "mx". You can change it as you wish so typing



layout="absolute"
minWidth="1024" minHeight="768">



will be ok, but... Follow the white rabbit(The Rules) !

If you change to super and accessor will be mx



layout="absolute"
minWidth="1024"
minHeight="768">



"The prefix "super" for element "super:Application" is not bound."

If you change the namespace to super and live the "mx"



layout="absolute"
minWidth="1024"
minHeight="768">



it will throw you error again "The prefix "mx" for element "mx:Application" is not bound."

Cause it couldn't find the namespace for your prefix in the component definition.

So what when you want expose some of your components. You can add the same namespace but with different prefix ex.



xmlns:super="http://www.adobe.com/2006/mxml"
layout="absolute"
minWidth="1024"
minHeight="768">



remember

you cannot duplicate the namespaces with same accessor

xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
minWidth="1024"
minHeight="768">



is wrong cause there cannot be two "mx" accessors


If you ever created custom flex component and you placed it for ex. in my.beutiful.components.*
your namespace will be the path to them and you can name your accessor as you wish - ex. you can type:



xmlns:super="my.beautiful.components.*"
layout="absolute"
minWidth="1024"
minHeight="768">





If you have only one component from my.beautiful.components.* it will be correct to also type:



layout="absolute"
minWidth="1024"
minHeight="768">



So you can refactor your application without remember to clean out your main container namespace.


Well you if you don't follow the rules you can now type:




xmlns:display="flash.display.*"
width="100%" height="100%">



But please don't do this :D


Well what's with as3 ? Why we need namespaces ? Let's see flex again and will create some more magic canvas



package my.beautiful.components
{
import mx.containers.Canvas;

public class SuperCanvas extends Canvas
{
public function SuperCanvas()
{
super();
}
}
}

Simply add some default flex namespace to it called mx_internal



package my.beautiful.components
{
import mx.containers.Canvas;
import mx.core.mx_internal;

use namespace mx_internal

public class SuperCanvas extends Canvas
{
public function SuperCanvas()
{
super();
}
}
}

Now we can access all the mx_internal functions and properties and change them - sometimes it is very handy. Especially when creating custom components.

To check what functions are mx_internal by Ctrl+Space eclipse shortcut you need some Flash Builder beta. Just grab one from adobe labs site
You simply type there override mx_internal function and the shortcut (Ctrl+Space) and here we go - all the mx_internal functions pop up in the window.

We will use some mx_internal stuff now to change something simple:



package my.beautiful.components
{
import mx.containers.Canvas;
import mx.core.ScrollPolicy;
import mx.core.mx_internal;

use namespace mx_internal

public class SuperCanvas extends Canvas
{
public function SuperCanvas()
{
super();
_horizontalScrollPolicy = ScrollPolicy.ON;
_verticalScrollPolicy = ScrollPolicy.OFF;
}
}
}

We set the scroll policy in the canvas directly not trough reference. So to be clear - you use your namespace to cover some of your code, that you don't want the not experienced user to use directly.
Some user with your code can do something like that:



package my.beautiful.components
{
import mx.containers.Canvas;
import mx.controls.Button;
import mx.core.ScrollPolicy;
import mx.core.mx_internal;

use namespace mx_internal

public class SuperCanvas extends Canvas
{
public function SuperCanvas()
{
super();
_horizontalScrollPolicy = ScrollPolicy.ON;
_verticalScrollPolicy = ScrollPolicy.OFF;
}

override public function set horizontalScrollPolicy(value:String) : void {
//
}

override public function get horizontalScrollPolicy() : String {
return ScrollPolicy.AUTO
}
}
}

If you need to use some of the method in other class not by inheritance and don't want to expose it to the world use namespace

keep looking at the Fex SDK source code and learning, I hope that I helped you

piątek, 31 lipca 2009

custom Flex component Basics

When you explore all the components and there wont be anything left. You know how to design layout of your application using some HBox, VBox, or Canvas. Sometimes you want to make something new.

Maybe a new sandwich cause you are hungry while waiting for pizza.

But sometimes you really want to make some brand new component to stay between those written by Adobe guys.

If you came here and still want to do this keep reading and you maybe do some.

So where to start ?

Well there are 2 ways:

The hard one:

First you need to know that Flex framework is not the bunch of MXML components but it's build on top of flashplayer purely in Actionscript 3. Yes all the flex components are build in Actionscript and if you know some Object Oriented Programming you are now definitely not reading this post but start exploring.

Well you can. But there is not only the advanced part that you must extend and build everything on top of some class keeping everything strict to framework rules extending / updating etc.

And the simple one:

You can make new components directly in MXML just using something called itemRenderer

Item Renderer cannot be changed on every components. Why you want to change it on buttons ? :>

It can be changed on every component that consist more then one data object. Simply that have dataProvider attribute. Well that's combobox, list or datagrid.

Let's make a simple list displaying application:





One
Two
Three




Well it only displays a list of 3 strings something like that
One
Two
Three
Not much you can say but let's make some custom component to display my list named ListItem.mxml
Base it on





override public function set data(value:Object):void {
super.data = value;
test.text = (data as String).charAt();
}
]]>




The magic here is with override the function to set data I added onle line to set some data for my . The data I get to my ListItem is the current position from dataProvider passed to our custom component so the data will be: One, Two, Three. Everything else so generating multiple ListItem components as more the data you have is done automatic in my Flex List component I only care of the look of my itemRenderer
Well... I hope you get it.
To prove I also added some simple rollOver / rollOut actions to my label that will display full name of the data when you roll over on that Label (notice that your events are in that LabelItem not in the main application)
The LabelItem looks now like this:





override public function set data(value:Object):void {
super.data = value;
test.text = (data as String).charAt();
}

private function rollOverHandler():void {
test.text = data as String;
}

private function rollOutHandler():void {
test.text = (data as String).charAt();
}
]]>





The second magic is add to my list the class to the itemRenderer parameter.
Simply itemRenderer="the.place.where.my.component.is.MyComponent".
Well my component is in the same path that my application so I simply put the string with my component name:





One
Two
Three





And that's it now when you build your project you get your unique List component.
Well...
You can pass whatever you want to your dataprovider class and then receive only one item for your itemRenderer.
Ex. you get multiple VOs that have image urls and labels (let's name it ImageVO) and you want to display it in your flex application. All you need is List
the sample itemRenderer will look similar to above but we will add Image component that will autoLoad our images and display it as 40x40px
so the code will look like this





override public function set data(value:Object):void {
super.data = value;
test.text =(data as ImageVO).title
img.source = (data as ImageVO).url;

}

]]>






Easy enough ? Well that's basic.
Next time I try to show you how to display bigger image when you roll over on that 40x40 one just with simple code. You can try yourself using toolTip property

Have fun and happy coding with flex that's easy

środa, 29 lipca 2009

Nice Adobe LiveCycle ES contest

Well adobe will soon release their next version of LiveCycle so they made a contest

Prizes are good, thats what they wrote on their site:

First Prize:

Free Pass to MAX 2009 AND Creative Suite 4 Master Collection

Second Prize:

Free Pass to MAX 2009 OR Creative Suite 4 Master Collection

Honorable Mentions:

Acrobat Professional Extended

More on their site:

http://demo.host.adobe.com/M3/contest.html

Good luck

piątek, 24 lipca 2009

AJournal simple logger to file for AIR applications

Well, when I came back from work I did a research to find out any AIR application specified logger and there is no any :/

Since we can write anything to file there should be something that allow us to do that ...  and now there it is.

http://code.google.com/p/ajournal/ that's the small child I give You.

Well it's some kind of wrapper to flex logging to add files support. I made it singleton so it can be used as simple as was  possible. In the download archive and in the source in svn there is a mxml file with basic sample code. Maby the class is not perfect but hey it's working and making all I need for now.

It has abilities to log to files with different names, wow ! ...  more on the project page.  I'll try to upragde the version this weekend to eliminate the TODO list. If anyone will use it except me.

Enjoy

wtorek, 12 maja 2009

Customize your FlexBuilder appearance screen

Day after day I was looking on the same apperance screen when my FlexBuilder is starting. I thought changing the screen will be very hard to do but I tried :) And now my screen is changed yey :)


So how to do that ?


Well it's very simple - that's the same directory both on mac and windows but different path.


All you need to do is:
1. Find your eclipse plugins directory on vista that can be ex. "C:\Program Files\Adobe\Flex Builder 3\plugins"


2. Find the folder named com.adobe.flexbuilder.standalone_3.0.214193.
the numbers might be different - I think it depends on version of your flex builder.


3. The directory contains some bmp files with flexbuilder screen. Just change it with the custom bmp and that's it.


You changed your screen :)

wtorek, 7 kwietnia 2009

Simple actionscript logging via socket with python socket server

So you want simple logging to external resources.

ex. live your application working for a long night and then check how it was doing it's job

try something like that:

first we will setup simple socket server - without any extensions only one single connection

#-*- coding: utf-8 -*-

import socket
import sys


hostname = 'localhost'
port = 2000
if len(sys.argv) < 3:
print 'For custom: %s [host name] [port number]' % sys.argv[0]
#sys.exit(1)
else :
hostname = sys.argv[1]
port = int(sys.argv[2])
print 'now is', hostname, port
# makes socket server
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

# add socket to port and listen
sock.bind((hostname, port))
sock.listen(1)
print '--- Logging started ---'

# service of the response
request, clientAddress = sock.accept()
# send some message
request.send('Is logging --- simple python logger --- 0.0.1 alpha')
while 1:
data = request.recv(1024)
if data :
print str(data)
else :
#stop logging
print '--- Logging stopped ---'
sock.close()
break


then we want some simple logging class

package pl.vane.logging
{
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.SecurityErrorEvent;
import flash.net.Socket;

public class ALog
{

private static var socket:Socket

private static var _host:String;
private static var _port:int;

private static var _connected:Boolean = false;

public function ALog()
{

}

//--------------- PUBLIC ------------------

public static function initLogging(host:String = 'localhost', port:int = 2000):void
{
_host = host;
_port = port;

socket = new Socket();

socket.addEventListener(Event.CONNECT, conn);
socket.addEventListener(ProgressEvent.SOCKET_DATA, data);
socket.addEventListener(IOErrorEvent.IO_ERROR, error);
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, error);

try
{
socket.connect(_host, _port);
}catch(e:Error)
{
trace(e);
}
}

public static function connect():void {
try
{
socket.connect(_host, _port);
}catch(e:Error)
{
trace(e);
}
}

public static function isLogging():Boolean {
return _connected;
}

public static function log(t:ALogType, message:String):void
{
if(socket.connected) {
var s:String = t.type+': '+message;
socket.writeUTFBytes(s);
socket.flush();
} else {
trace('ALog not connected');
}

}

public function toString():String {
return 'pl.vane.logging.ALog'
}

//--------------- PRIVATE ------------------
private static function conn(e:Event):void {
if(socket.connected)
{
_connected = true;
}
}

private static function data(e:ProgressEvent):void
{
if(socket.connected)
{
var s:String = socket.readUTFBytes(socket.bytesAvailable);
trace('LOGGING RESPONSE: ', s);
}
}

private static function error(e:Event):void
{
trace(e);
}

}
}


and I added some usefull headers with types to the message

package pl.vane.logging
{
public class ALogType
{

public static const WARN:ALogType = new ALogType('WARN');
public static const ERROR:ALogType = new ALogType('ERROR');
public static const INFO:ALogType = new ALogType('INFO');
public static const LOG:ALogType = new ALogType('LOG');
public static const DUMP:ALogType = new ALogType('DUMP');

private var _type:String;

public function ALogType(type:String)
{
_type = type;
}

public function get type():String
{
return _type;
}

public function toString():String {
return 'pl.vane.logging.ALogType'
}

}
}


well it won't be perfect but it's working :)
so simple work with AIR application will be something like this




import pl.vane.logging.*;
import flash.utils.clearInterval;
import flash.utils.setInterval;

private var logInterval:uint;

private function complete():void
{
ALog.initLogging();
logInterval = setInterval(initLogging, 1000);
}

private function initLogging():void {
if(ALog.isLogging()) {
// state complete
ALog.log(ALogType.DUMP, 'start of socket logger');
clearInterval(logInterval);
return
} else {
ALog.connect();
trace('not logging');
}
}
]]>





first we initialize the logging interface by calling

ALog.initLogging();

then if it fails we are setting the interval by calling simply

Alog.connect()

via interval function
if it logs the method

ALog.isLogging()

returns true so we can send some message and clear interval

in this example we can try send messages with pressing the button for test :)

happy logging

poniedziałek, 6 kwietnia 2009

1...2...3 syntax highlight

1. Python syntax test - some request code
 
import urllib2
import threading

# Code for continous request http://www.google.pl
print "Get some data"
request = urllib2.Request('http://www.google.pl/')
request.add_header('User-Agent', 'Mozilla')
handler = urllib2.HTTPHandler()
opener = urllib2.build_opener(handler)
data = opener.open(request).read()
thread = threading
# Methods
# make new request in 30 seconds
def runTimer():
timer = None
timer = thread.Timer(30, secondRequest)
timer.start()

# second request
def secondRequest():
seconddata = opener.open(request).read()
data = 'null'
runTimer()
print 'request'

print 'request'
runTimer()



2. MXML Syntax Test - some socket


creationComplete="handleComplete(event)">

import mx.core.UIComponent;
import mx.messaging.channels.NetConnectionChannel;
private var socket:Socket;

private function handleComplete(e:Event):void {
var ui:UIComponent = new UIComponent;
}

private function connect():void {
socket = new Socket();
socket.addEventListener(Event.CONNECT, handleConnect)
socket.addEventListener(ProgressEvent.SOCKET_DATA, handleData);
try {
socket.connect('localhost', 2000);
} catch(e:Error) {
trace(e.toString());
}
}

private function handleData(e:ProgressEvent):void {
if(socket.connected) {
responseText.text+= socket.readUTFBytes(socket.bytesAvailable);
}
socket.close();
}

private function handleConnect(e:Event):void {
responseText.text += 'socket connected\n'
}
]]>







3. ActionScript 3 Syntax Test - some preloader stuff

package pl.vane.preloader.
{
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.system.Capabilities;

import mx.events.FlexEvent;
import mx.preloaders.DownloadProgressBar;

public class CustomPreloader extends DownloadProgressBar
{

[Embed(source="../../../../../assets/logo.jpg")]
private var LOGO:Class;

private var _startupBMP:Bitmap;

private var p:Sprite;

public function CustomPreloader()
{
super();
_startupBMP = new Bitmap(Bitmap(new LOGO()).bitmapData);
addChild(_startupBMP);
addEventListener(Event.ADDED_TO_STAGE, add);
}

private function add(e:Event):void {
stage.addEventListener(Event.RESIZE, resizeElements);
_startupBMP.x = (Capabilities.screenResolutionX - _startupBMP.width) * .5;
_startupBMP.y = (Capabilities.screenResolutionY - _startupBMP.height) * .5;
}

override public function set preloader(preloader:Sprite):void {
p = preloader;
p.addEventListener(FlexEvent.INIT_COMPLETE, initEnd);
}

// Event listeners for the FlexEvent.INIT_COMPLETE event.
private function initEnd(event:Event):void {
event.preventDefault();
stage.removeEventListener(Event.RESIZE, resizeElements);
p.removeEventListener(FlexEvent.INIT_COMPLETE, initEnd);
cp();
}

private function cp():void {
dispatchEvent(new Event(Event.COMPLETE));
}

private function resizeElements(e:Event):void {
centerElements();
}

private function centerElements():void {
_startupBMP.x = (Capabilities.screenResolutionX - _startupBMP.width) * .5;
_startupBMP.y = (Capabilities.screenResolutionY - _startupBMP.height) * .5;
}

}
}