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;
}

}
}

1 komentarz: