Oracle NLS_LANG & JDBC probs

Some friends were facing character encoding problems on an oracle db.
Well the origin of this problem is that when you install an oracle,
in this case it was a 9i, the NLS_LANG param (if not defined) is set to
AMERICAN_AMERICA.US7ASCII. The language is AMERICAN,
the country is AMERICA, and the character set is US7ASCII.
This is really a problem if you live in Germany and you want to
work with german charachters & CLOB :)

The best way to avoid problems with the old JDBC they are using, is
to install the DB once again with an UTF8/16. But this is not possible.
There are also some other dependencies for these guys so the best way
for their workflow ist to do an exp, drop the user and imp again. Than
connect with the SQLDeveloper and recheck the CLOB.

 sql |  copy |? 
01
02
exp scott/tiger filename=mydump.dmp
03
 
04
sqlplus scott/tiger
05
	DROP USER scott CASCADE;
06
	CREATE USER scott IDENTIFIED BY tiger;
07
	GRANT CONNECT,RESOURCE,UNLIMITED TABLESPACE TO scott IDENTIFIED BY tiger;
08
 
09
imp scott/tiger filename=mydump.dmp
10

than sqldeveloper But please use SQL Developer with causion ! It sucks.

http://privatefunction.net/wp-content/plugins/sociofluid/images/digg_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/delicious_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/technorati_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/google_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/facebook_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/mixx_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/twitter_32.png

Synchronize – pull using rsync

Yesterday a guy was claiming that he had to copy all counterstrike source files from one server to another. He was telling that this takes a lot of time because he had to sftp to desktop and than upload to server.
Well rsync can do this much quicker and better. I wrote a few years ago this little script called my_syncmokey.

 shell script |  copy |? 
01
02
#!/bin/bash
03
echo "***************************************************************"
04
echo "*                                                             *"
05
echo "*                    - Your Sync Monkey started -             *"
06
echo "***************************************************************"
07
echo
08
echo
09
10
#Logfile
11
LOGFILE="PATH/TO/YOUR/LOG.log".`date '+%Y%m%d_%H%M%S'`
12
13
#config
14
SERVER="IP FROM THE SERVER YOU WANT TO PULL"
15
REMOTEDIR="/PATH/TO/THE/REMOTE/FOLDER"
16
LOCALDIR="/PATH/TO/THE/LOCAL/FOLDER "
17
SSH="/usr/bin/ssh"
18
19
#output
20
echo >> $LOGFILE;
21
echo "- Sync Monkey started -" >> $LOGFILE;
22
echo >> $LOGFILE;
23
echo "Timestamp: " `date '+%Y%m%d %H%M%S'` >> $LOGFILE;
24
echo >> $LOGFILE;
25
echo >> $LOGFILE;
26
echo "command: rsync -av --links --rsh=$SSH $SERVER:$REMOTEDIR $LOCALDIR " >> $LOGFILE;
27
echo >> $LOGFILE;
28
29
#sync and write to logfile
30
rsync -av --links --rsh=$SSH $SERVER:$REMOTEDIR $LOCALDIR >> $LOGFILE;
31
32
#print output
33
cat $LOGFILE | while read line
34
do
35
echo $line
36
done
37
38

http://privatefunction.net/wp-content/plugins/sociofluid/images/digg_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/delicious_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/technorati_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/google_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/facebook_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/mixx_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/twitter_32.png

Serious Opinion – Flash, Apple & change

Last weekend I had to answer many questions about Mr. Jobs "Thoughts on Flash".
“What is your serious opinion?”
This thought are something I want to share with you. First I find Mr. Jobs words hypocritical for many reasons. Just to make it short:

“Adopting technologies quickly”
Apple just shipped a year ago the finder in cocoa and other programs are still running on carbon e.g. Final Cut. Dear Apple why did this take so long?
Itunes on Windows is crap. Why does apple not take advantage of the new features of Windows? Apple changed iPhone SDK Agreement so that applications should take advantage of Iphone OS so why they don’t take advantage of new Windows?

“open”
I think all this open bla bla should mask that H.264 is not open! Microsoft & Apple, both members of MPEG-LA, are going to make money with this video codec because it is proprietary and patented. So in Apple’s eyes if the specification of software is free than we can call this open standard? Fine, than Flash is an open standard too.
However, Apple sucks – this is something I was saying for years now. I did not make many friends with this statement at last Adobe MAX. Now I’m looking forward to meet those people and I’m curious if they are still so proud of using MAC Book Pro.

But what is the essence of this discussion?

A few years ago everyone was claiming that software inside the browser is the next BIG THING e.g. Gmail. Now I have the feeling the trend is going more and more towards apps. People are starting to use Apps for things, which could run inside the browser.Not only because of new ways of interaction e.g. Multitouch…

This shows that something is wrong with the web and with content that runs inside the browser. It doesn’t matter if HTML or Flash. And we should keep in mind that apps are not “open”.
I think the Web is loosing sexiness, web apps like Gmail etc. are far away to offer features like mobile/desktop apps do. (Non web apps are also often much faster).
This leak of features is something that the Browser must close. Mozilla and Chrome are on the right way. They must give Developer the option to do more than only W3C “adaption”. But I also know this is not simple…..

I met yesterday a good friend who has a c level position. And he asked me if I would still recommend developing an API for their business. Sure you should! Because it give’s you the option to deliver your content anywhere (Apps or Web) and to track it.  This flexibility is something important for your business……..

What about Flash?

Flash has currently around 98% penetration thus it is not dead! Also HTML5 Browser propagation is poor at the moment. (I still have lots of customers & their consumers that use IE6) I don’t know currently when Google will roll-out VP8 on Youtube. This could change the game. Honestly, I never liked Flash. Not because of its technology. I don’t like flash because it’s mostly misused.

http://privatefunction.net/wp-content/plugins/sociofluid/images/digg_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/delicious_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/technorati_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/google_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/facebook_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/mixx_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/twitter_32.png

Experiment HTML5 Particles and Audio Data API Spectrum

HTML 5 Experiment

I had a few days ago a couple of minutes and I wanted to take a look into three.js.
I had the idea to use Audio Data API to get the sound spectrum of a song and combine this with three.js particles.
Just for an experiment…

As I needed a song that I could use without get fucked by those labels/artists I started a CC search and found Galdson’s Denilio – awesome.

A few minutes later the Experiment was ready and started. And it was so beautiful in my Eyes! But my computer is really crappy so I couldn’t enjoy and my time was over too…

Yesterday I started the experiment and I was unhappy again because of performance issues. But this was the original purpose of the Experiment, get a feeling for performance…..

Anyway I hacked a quick FPS keeper and voilá.

I promised to share but first you will need a Mozilla with the Audio Data API you can get it here:

Linux:
firefox-3.7a1pre.en-US.linux-i686
Mac builds:
10.5
10.6
Windows:
firefox-3.7a1pre.en-US.win32
The Experiment is here
cheers

http://privatefunction.net/wp-content/plugins/sociofluid/images/digg_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/delicious_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/technorati_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/google_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/facebook_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/mixx_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/twitter_32.png

From back to front

Wow, now it’s April and this is the first post in 2010. So you can imagine how busy I’ve been the last months.

I also have to apologize!(special @FxDev) I’m really sorry – lot of amazing projects took a back seat. But it’s now changing like live changes.
I’m leaving my current job. I currently don’t know what’s coming but it’s going to be amazing! I also hope to improve live – work balance.

This means:

  • I’m accepting now Dj bookings again, so keep your ears open, new mixes will be available soon.
  • developing new visualizations
  • I’m going to start again posting here!! Not only Code – now also a lot of other stuff that I couldn’t talk about before.

I’m really looking forward – this will be fun – and I hope those Trolls will disappear step by step.

so keep eyes and ears open!

http://privatefunction.net/wp-content/plugins/sociofluid/images/digg_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/delicious_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/technorati_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/google_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/facebook_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/mixx_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/twitter_32.png

Special December Mix

silentium

Silentium

 

http://privatefunction.net/wp-content/plugins/sociofluid/images/digg_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/delicious_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/technorati_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/google_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/facebook_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/mixx_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/twitter_32.png

Updateted : How to write Jpeg || Png Files in Swf Files

Today I wrote a new Class using swf assist for writing Jpeg or PNG files to a SWF File.

Now you could use :

 actionscript3 |  copy |? 
1
_imagePro = new ImageToSwfProcessor();
2
_imagePro.addEventListener(ImageProcessorEvent.NEXT_FILE, handleNextFile, false, 0, true);
3
_imagePro.writeSwfFromImage(image:*,quality : int ,"png" || "jpeg" : String, framecount : int);

Method wirteSwfFromImage has some Parameters.

1) The decent File as swf, jpeg or what else.

2) quality is used if image is jpeg or swf.

3) type is used to determ the current file. Only png or jpeg are used

4) framecount used to increment frames.

The Listener is called if you have many Files to store in a swf file. After each swf writing Process that listener would dispatch.

Here is that one.

 actionscript3 |  copy |? 
001
/**
002
 * Copyright 04.09.2009 Christian Sobolewski
003
 * 
004
 * usage : com.cs.imageProcessor
005
 * 
006
 * Parameters:
007
 * 
008
 * Version:
009
 * 
010
 * History:
011
 * 
012
 * com.cs.imageProcessor.ImageProcessor
013
 * @author Christian Sobolewski
014
 */
015
package com.cs.imageProcessor {
016
	import com.adobe.images.JPGEncoder;
017
	import com.adobe.images.PNGEncoder;
018
	import com.cs.logging.SOS;
019
 
020
	import org.libspark.swfassist.io.ByteArrayOutputStream;
021
	import org.libspark.swfassist.swf.io.SWFWriter;
022
	import org.libspark.swfassist.swf.io.WritingContext;
023
	import org.libspark.swfassist.swf.structures.FillStyle;
024
	import org.libspark.swfassist.swf.structures.FillStyleTypeConstants;
025
	import org.libspark.swfassist.swf.structures.SWF;
026
	import org.libspark.swfassist.swf.structures.ShapeWithStyle;
027
	import org.libspark.swfassist.swf.structures.StraightEdgeRecord;
028
	import org.libspark.swfassist.swf.structures.StyleChangeRecord;
029
	import org.libspark.swfassist.swf.tags.DefineBitsJPEG3;
030
	import org.libspark.swfassist.swf.tags.DefineShape;
031
	import org.libspark.swfassist.swf.tags.PlaceObject2;
032
	import org.libspark.swfassist.swf.tags.SetBackgroundColor;
033
	import org.libspark.swfassist.swf.tags.ShowFrame;
034
 
035
	import flash.display.BitmapData;
036
	import flash.display.Sprite;
037
	import flash.events.Event;
038
	import flash.events.EventDispatcher;
039
	import flash.events.IOErrorEvent;
040
	import flash.events.MouseEvent;
041
	import flash.events.ProgressEvent;
042
	import flash.events.SecurityErrorEvent;
043
	import flash.net.FileReference;
044
	import flash.utils.ByteArray;
045
 
046
	/**
047
	 * @author Christian Sobolewski
048
	 */
049
	public class ImageToSwfProcessor extends EventDispatcher {
050
 
051
		private var _swf : SWF;
052
		private var _bytes : ByteArray;
053
		private var _fileRef : FileReference;
054
		private var _name : String;
055
		private var _eof : Sprite;
056
 
057
		public function ImageToSwfProcessor() {
058
		}
059
 
060
		public function writeSwfFromImage(image : *, quality : int, type : String , frames : int = 1, bgColor : int = 0x000066) : BitmapData {
061
			_name = image.name.split(","+type).join("").toString();
062
 
063
			var w : Number = image.width;
064
			var h : Number = image.height;
065
 
066
			_swf = new SWF();
067
			_swf.header.version = 9;
068
			_swf.header.isCompressed = false;
069
			_swf.header.frameSize.xMax = image.width;
070
			_swf.header.frameSize.yMax = image.height;
071
			_swf.header.frameRate = 1;
072
			_swf.header.numFrames = 1;	
073
 
074
			var bg : SetBackgroundColor = new SetBackgroundColor();
075
			bg.backgroundColor.fromUint(bgColor);
076
			_swf.tags.addTag(bg);
077
 
078
			var bmd : BitmapData;
079
 
080
			if (type == "png") {
081
				bmd = new BitmapData(w, h, true, 0x000000ff);
082
				bmd.draw(image);
083
				_bytes = PNGEncoder.encode(bmd);
084
			} else {
085
				bmd = new BitmapData(w, h, false);
086
				bmd.draw(image);
087
				_bytes = new JPGEncoder(quality).encode(bmd);
088
			}		
089
 
090
//			SOS.alert("image.width = " + image.width);
091
//			SOS.alert("image.height= " + image.height);
092
 
093
			for (var i : uint = 0;i < frames;++i) {
094
 
095
				var defineJPEG : DefineBitsJPEG3 = new DefineBitsJPEG3();
096
				defineJPEG.characterId = (i * 2) + 1;
097
				defineJPEG.jpegData = _bytes;
098
 
099
				_swf.tags.addTag(defineJPEG);
100
 
101
				var defineShape : DefineShape = new DefineShape();
102
				defineShape.shapeId = (i * 2 + 1) + 1;
103
				defineShape.shapeBounds.xMax = w;
104
				defineShape.shapeBounds.yMax = h;
105
				var fillStyle : FillStyle = new FillStyle();
106
				fillStyle.fillStyleType = FillStyleTypeConstants.CLIPPED_BITMAP_FILL;
107
				fillStyle.bitmapId = (i * 2) + 1;
108
				fillStyle.bitmapMatrix.hasScale = true;
109
				fillStyle.bitmapMatrix.scaleX = 0;
110
				fillStyle.bitmapMatrix.scaleY = 0;
111
				var shape : ShapeWithStyle = defineShape.shapes;
112
				shape.fillStyles.fillStyles.push(fillStyle);
113
				var r1 : StyleChangeRecord = new StyleChangeRecord();
114
				r1.fillStyle0 = 1;
115
				r1.moveDeltaX = 0;
116
				r1.moveDeltaY = 0;
117
				r1.stateFillStyle0 = true;
118
				r1.stateMoveTo = true;
119
				var r2 : StraightEdgeRecord = new StraightEdgeRecord();
120
				r2.verticalLine = true;
121
				r2.deltaY = h;
122
				var r3 : StraightEdgeRecord = new StraightEdgeRecord();
123
				r3.horizontalLine = true;
124
				r3.deltaX = w;
125
				var r4 : StraightEdgeRecord = new StraightEdgeRecord();
126
				r4.verticalLine = true;
127
				r4.deltaY = -h;
128
				var r5 : StraightEdgeRecord = new StraightEdgeRecord();
129
				r5.horizontalLine = true;
130
				r5.deltaX = -w;
131
				shape.shapeRecords.push(r1, r2, r3, r4, r5);
132
 
133
				_swf.tags.addTag(defineShape);
134
 
135
				var placeObject : PlaceObject2 = new PlaceObject2();
136
				placeObject.characterId = (i * 2 + 1) + 1;
137
				placeObject.depth = i + 1;
138
				placeObject.hasCharacter = true;
139
 
140
				_swf.tags.addTag(placeObject);
141
				_swf.tags.addTag(new ShowFrame());
142
				_swf.header.numFrames++;
143
			}
144
 
145
 
146
			var swfBytes : ByteArray = new ByteArray();
147
 
148
			var wc : WritingContext = new WritingContext();
149
			//			wc.length = 5000;
150
 
151
			var write : SWFWriter = new SWFWriter();
152
			write.writeSWF(new ByteArrayOutputStream(swfBytes), wc, _swf);
153
 
154
			_fileRef = new FileReference();
155
			_fileRef.addEventListener(Event.COMPLETE, handleCompleteEvent, false, 0, true);
156
			_fileRef.addEventListener(ProgressEvent.PROGRESS, handleProgressEvent, false, 0, true);
157
			_fileRef.addEventListener(Event.CANCEL, handleCancelEvent, false, 0, true);
158
			_fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleSecurityEvent, false, 0, true);
159
			_fileRef.addEventListener(IOErrorEvent.IO_ERROR, onSaveError, false, 0, true);
160
			_fileRef.addEventListener(Event.OPEN, onOpen, false, 0, true);
161
 
162
			_fileRef.save(swfBytes, _name + ".swf");
163
 
164
			/**
165
			 * strange things happen here. if you dont activate Event.ENTER_FRAME no Event.COMPLETE will fire !!! 
166
			 */
167
 
168
			_eof = new Sprite();
169
			_eof.addEventListener(Event.ENTER_FRAME, handleEof, false, 0, true);
170
 
171
			return bmd;
172
		}
173
 
174
		private function handleEof(event : Event) : void {
175
			if(_fileRef.data) SOS.alert(_fileRef.data);
176
		}
177
 
178
		private function onOpen(event : Event) : void {
179
//			SOS.alert('onOpen: ' + (onOpen));
180
		}
181
 
182
		private function handleClick(event : MouseEvent) : void {
183
//			SOS.alert('handleClick: ' + (handleClick));
184
		}
185
 
186
		private function onSaveError(event : IOErrorEvent) : void {
187
//			SOS.alert('onSaveError: ' + (onSaveError));
188
		}
189
 
190
		private function handleSecurityEvent(event : SecurityErrorEvent) : void {
191
//			SOS.alert('handleSecurityEvent: ' + (handleSecurityEvent));
192
		}
193
 
194
		private function handleCancelEvent(event : Event) : void {
195
//			SOS.alert("cancel event");
196
		}
197
 
198
		private function handleProgressEvent(event : ProgressEvent) : void {
199
			SOS.alert(event.bytesLoaded + " | " + event.bytesTotal);
200
		}
201
 
202
		private function handleCompleteEvent(event : Event) : void {
203
			if (_eof.hasEventListener(Event.ENTER_FRAME)) _eof.removeEventListener(Event.ENTER_FRAME, handleEof);
204
			dispatchEvent(new ImageProcessorEvent(ImageProcessorEvent.NEXT_FILE))
205
//			SOS.alert("save complete");
206
		}
207
	}
208
}
209

http://privatefunction.net/wp-content/plugins/sociofluid/images/digg_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/delicious_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/technorati_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/google_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/facebook_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/mixx_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/twitter_32.png

Palm Pre mit Vodafone und Daten Flat

update:
ich habe eben noch mal mit Vodafone telef. aufgrund, das die änderung in wap.vodafone.de

nur GPRS empfang ergab. Und das ist auch richtigt ! Siehe http://www.vodafone.de/konfig

aber GPRS suckt ja ordentlich. Für Umts braucht man einen Vodafone Daten Tarif was ich auch hab’

also sind keine Änderungen nötig !!! Die Änderung, die unten beschrieben wird gilt nur für den Vodafone Life! Tarif !!


Ich habe mir gestern das Pre besorgt, schick schick aber ich habe Vodafone mit Datenflat bedeutet,
das man eine kleine Einstellung beim Pre vornehmen muss um nicht in die Kostenfalle zu tappen.

Aber Achtung – bitte vorher bei Vodafone anrufen und sich nach dem eigenen Tarif erkundigen.
Aber Achtung – alle änderungen die nun folgen sind auf eigene Gefahr !!

Das mini Tutorial erfordert schon fortgeschrittene Kenntnisse ansonsten könnt’s eng werden.

1. Root
Einen guten howto für den Root Zugang habe ich hier gefunden Palm Pre Root Zugang also dann erstma “bis später …”

2. APN
man muss den richtigen APN Zugangspunkt eingeben dafür habe ihr jetzt ja auch den root zugang. Also
putty öffnen und in die console

  |  copy |? 
1
cp /usr/lib/luna/CarrierNetworkSettings.db3 /media/internal

damit habt ihr die Datei CarrierNetworkSettings.db3 in einem für euch zugängliches Verzeichnis kopiert.

Jetzt einfach über den usb Modus die Datei auf euren Rechner übertragen.
Die Datei ist eigentlich eine kleine Datenbank des Typs Sqlite. Dort befinden sich die APN Zugänge.

Achtung ! – Eine Sicherungskopie der CarrierNetworkSettings.db3 anlegen. Falls was schief geht …..

Jetzt müssen wir diese Datei editieren. Ich persönlich finde den sqlite-manager am Besten !! Plattform unabhängig und klein wie Sqlite. Also installieren.

Jetzt habt ihr im FF unter Extras den sqlite-manager damit mach ihr die CarrierNetworkSettings.db3 auf dort müsst ihr unter
com_palm_data_carriernetworksettings_DataConnectionSettings mal die suche öffnen und auf das Feld APN contains web
eingeben.
apn-sql-lite-palmpre-vodafone
dort das feld web.vodafone.de mit wap.vodafone.de ersetzen und fertig.

Zur Sicherheit könnt Ihr noch die Tabelle durchsuchen ob da noch irgendwo web steht. Dies sollte nicht der Fall sein.
Mir ist von Vodafone gesagt worden, das die Flatrate nur für den APN wep gilt. Sollte man über web gehen wird’s teuer !!
Hier könnt ihr aber auch noch mit der Hotline reden über mehr Info’s bin ich auch dankbar.
!! Bitte über den Quick check im vodafone Portal mal ständig den Rechnungsstatus checken !!

So jetzt müssen wir die CarrierNetworkSettings.db3 irgendwie wieder zurück schaufeln dafür nutze ich

WebOS Quick Install

Wenn WebOS Quick Install bei euch läuft müsst ihr nur auf Tools -> Sendfile gehen und die überarbeitete db3 in die Verzeichnisse

  |  copy |? 
1
/usr/lib/luna/ 
&
  |  copy |? 
1
/var/luna/data/
kopieren.

das wars’.

Schon 24h um und keine Kosten zu sehen.

http://privatefunction.net/wp-content/plugins/sociofluid/images/digg_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/delicious_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/technorati_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/google_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/facebook_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/mixx_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/twitter_32.png

How to save a SWF file at runtime with swfassist and FileReference

Here`s a little class to build a swf file at runtime with 2 images. Just an example :

Here you could find the swfassist framework. Unfortunately its not documented very well.
Just check out the svn for some examples.

JPGEncoder click here

I made a swf file with 20 frames, each frame the shown bitmap is switched. The swf could be saved locally on your Pc.

  |  copy |? 
001
002
/**
003
 * Copyright 31.08.2009 Christian Sobolewski
004
 * 
005
 * usage : 
006
 * 
007
 * Parameters:
008
 * 
009
 * Version:
010
 * 
011
 * History:
012
 * 
013
 * SwfWrite
014
 * @author Christian Sobolewski
015
 */
016
package {
017
	import com.adobe.images.JPGEncoder;
018
 
019
	import org.libspark.swfassist.io.ByteArrayOutputStream;
020
	import org.libspark.swfassist.swf.io.SWFWriter;
021
	import org.libspark.swfassist.swf.io.WritingContext;
022
	import org.libspark.swfassist.swf.structures.FillStyle;
023
	import org.libspark.swfassist.swf.structures.FillStyleTypeConstants;
024
	import org.libspark.swfassist.swf.structures.SWF;
025
	import org.libspark.swfassist.swf.structures.ShapeWithStyle;
026
	import org.libspark.swfassist.swf.structures.StraightEdgeRecord;
027
	import org.libspark.swfassist.swf.structures.StyleChangeRecord;
028
	import org.libspark.swfassist.swf.tags.DefineBitsJPEG2;
029
	import org.libspark.swfassist.swf.tags.DefineShape;
030
	import org.libspark.swfassist.swf.tags.PlaceObject2;
031
	import org.libspark.swfassist.swf.tags.RemoveObject2;
032
	import org.libspark.swfassist.swf.tags.SetBackgroundColor;
033
	import org.libspark.swfassist.swf.tags.ShowFrame;
034
 
035
	import flash.display.BitmapData;
036
	import flash.display.DisplayObject;
037
	import flash.display.Sprite;
038
	import flash.geom.Rectangle;
039
	import flash.net.FileReference;
040
	import flash.utils.ByteArray;
041
 
042
	/**
043
	 * @author Christian Sobolewski
044
	 */
045
	public class SwfWrite extends Sprite {
046
 
047
		private var _swf : SWF;
048
 
049
		[Embed(source="test.jpg")] 
050
		public var imgCls : Class;
051
 
052
		[Embed(source="logo.jpg")] 
053
		public var imgCls2 : Class;
054
 
055
		private var _pixels : ByteArray;
056
		private var _pixelsOne : ByteArray;
057
		private var _data : Array;
058
		private var _maxLength : uint;
059
 
060
		public function SwfWrite() {
061
 
062
			_maxLength = 20;
063
 
064
			var imgCls : DisplayObject = new imgCls();
065
			var imgCls2 : DisplayObject = new imgCls2();
066
 
067
			_swf = new SWF();
068
			_swf.header.version = 9;
069
			_swf.header.frameSize.xMax = 1024;
070
			_swf.header.frameSize.yMax = 768;
071
			_swf.header.frameRate = 2;
072
			_swf.header.numFrames = 1;
073
 
074
			var bgColor : SetBackgroundColor = new SetBackgroundColor();
075
			bgColor.backgroundColor.fromUint(0x000066);
076
			_swf.tags.addTag(bgColor);
077
 
078
			var bmd : BitmapData = new BitmapData(640, 480, false);
079
			bmd.draw(imgCls);
080
 
081
			_pixelsOne = new JPGEncoder(50).encode(bmd);
082
 
083
			var bmd2: BitmapData= new BitmapData(640, 480, false);
084
			bmd2.draw(imgCls2);
085
 
086
			_pixels = new JPGEncoder(50).encode(bmd2);
087
			_data = [];
088
			var q : Number;
089
			for (var i : int = 0;i < _maxLength;i++) {
090
				q = i % 2;
091
				if (q == 0) {
092
					_data.push(_pixelsOne);
093
				} else {
094
					_data.push(_pixels);
095
				}
096
			}
097
 
098
			test();
099
 
100
 
101
			var bytes : ByteArray = new ByteArray();
102
			var wc : WritingContext = new WritingContext();
103
			wc.length = 5000;
104
 
105
			var write : SWFWriter = new SWFWriter();
106
			write.writeSWF(new ByteArrayOutputStream(bytes), wc, _swf);
107
 
108
			var fileRef : FileReference = new FileReference();
109
			fileRef.save(bytes, "writen" + Math.random() + 100 + ".swf");
110
		}
111
 
112
		private function test() : void {
113
			for (var i : uint = 0;i < _maxLength;++i) {
114
				//				var file:File = File(files[i]);
115
 
116
				var defineJPEG : DefineBitsJPEG2 = new DefineBitsJPEG2();
117
				defineJPEG.characterId = (i * 2) + 1;
118
 
119
				//				var fileStream:FileStream = new FileStream();
120
				//				fileStream.open(file, FileMode.READ);
121
				//				fileStream.readBytes(defineJPEG.jpegData);
122
				//				fileStream.close();
123
				//				fileStream = null;
124
 
125
				defineJPEG.jpegData = _data[i];
126
 
127
				_swf.tags.addTag(defineJPEG);
128
 
129
				var defineShape : DefineShape = new DefineShape();
130
				defineShape.shapeId = (i * 2 + 1) + 1;
131
				defineShape.shapeBounds.xMax = 500;
132
				defineShape.shapeBounds.yMax = 375;
133
				var fillStyle : FillStyle = new FillStyle();
134
				fillStyle.fillStyleType = FillStyleTypeConstants.CLIPPED_BITMAP_FILL;
135
				fillStyle.bitmapId = (i * 2) + 1;
136
				fillStyle.bitmapMatrix.hasScale = true;
137
				fillStyle.bitmapMatrix.scaleX = 20;
138
				fillStyle.bitmapMatrix.scaleY = 20;
139
				var shape : ShapeWithStyle = defineShape.shapes;
140
				shape.fillStyles.fillStyles.push(fillStyle);
141
				var r1 : StyleChangeRecord = new StyleChangeRecord();
142
				r1.fillStyle0 = 1;
143
				r1.moveDeltaX = 50;
144
				r1.moveDeltaY = 50;
145
				r1.stateFillStyle0 = true;
146
				r1.stateMoveTo = true;
147
				var r2 : StraightEdgeRecord = new StraightEdgeRecord();
148
				r2.verticalLine = true;
149
				r2.deltaY = 375;
150
				var r3 : StraightEdgeRecord = new StraightEdgeRecord();
151
				r3.horizontalLine = true;
152
				r3.deltaX = 500;
153
				var r4 : StraightEdgeRecord = new StraightEdgeRecord();
154
				r4.verticalLine = true;
155
				r4.deltaY = -375;
156
				var r5 : StraightEdgeRecord = new StraightEdgeRecord();
157
				r5.horizontalLine = true;
158
				r5.deltaX = -500;
159
				shape.shapeRecords.push(r1, r2, r3, r4, r5);
160
 
161
				_swf.tags.addTag(defineShape);
162
 
163
				var placeObject : PlaceObject2 = new PlaceObject2();
164
				placeObject.characterId = (i * 2 + 1) + 1;
165
				placeObject.depth = i + 1;
166
				placeObject.hasCharacter = true;
167
 
168
				_swf.tags.addTag(placeObject);
169
				_swf.tags.addTag(new ShowFrame());
170
				_swf.header.numFrames++;
171
 
172
//				for (var fadeIn:uint = 0; fadeIn < 20; ++fadeIn) {
173
//					var fadeObject : PlaceObject2 = new PlaceObject2();
174
//					fadeObject.depth = i + 1;
175
//					fadeObject.isMove = true;
176
//					fadeObject.hasColorTransform = true;
177
//					fadeObject.colorTransform.hasMultiplication = true;
178
//					fadeObject.colorTransform.redMultiplication = 256;
179
//					fadeObject.colorTransform.greenMultiplication = 256;
180
//					fadeObject.colorTransform.blueMultiplication = 256;
181
//					fadeObject.colorTransform.alphaMultiplication = (((1.0 / 20) * 20) * 256);
182
//					_swf.tags.addTag(fadeObject);
183
//					_swf.tags.addTag(new ShowFrame());
184
//					_swf.header.numFrames++;
185
//				}
186
//
187
//				if (i > 0) {
188
//					var removeObject : RemoveObject2 = new RemoveObject2();
189
//					removeObject.depth = (i - 1) + 1;
190
//					_swf.tags.addTag(removeObject);
191
//				}
192
 
193
//				for (var n:uint = 0; n < len; ++n) {
194
//					_swf.tags.addTag(new ShowFrame());
195
//					_swf.header.numFrames++;
196
//				}
197
			}
198
		}
199
	}
200
}
201

http://privatefunction.net/wp-content/plugins/sociofluid/images/digg_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/delicious_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/technorati_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/google_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/facebook_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/mixx_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/twitter_32.png

Securimage PHP Captcha AS3 Class

about1

This CAPTCHA Class uses Securimage. You can get it here

Securimage is an open-source free PHP CAPTCHA script for generating complex images and CAPTCHA codes to protect forms from spam and abuse…

show.php

  |  copy |? 
1
2
include 'securimage.php';
3
$img = new securimage();
4
$img->show();
5

To load the created image, just write an URLLoader than a Loader, that loads the URLLoader data ….

Captcha.as

 as3 |  copy |? 
01
02
 public class Captcha extends Sprite
03
 {
04
 private var _loader:URLLoader;
05
 private var _captchadata:BitmapData;
06
 private var _captcha:Bitmap;
07
 private var _cont:Sprite;
08
09
 public function Captcha()
10
 {
11
 this._cont = new Sprite();
12
 this._cont.useHandCursor = true;
13
 this._cont.buttonMode = true;
14
15
 this._loader = new URLLoader();
16
 this._loader.dataFormat = URLLoaderDataFormat.BINARY;
17
 var url:String = "show.php";
18
 var urlReq:URLRequest = new URLRequest(url);
19
20
 this._loader.addEventListener(Event.COMPLETE, completeHandler);
21
 this._loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
22
 this._loader.load(new URLRequest(url));
23
 }
24
 private function ioErrorHandler(e:IOErrorEvent):void
25
 {
26
 //SOS.alert(_e.toString());
27
 }
28
 private function completeHandler(e:Event):void 
29
 {
30
 this._loader.removeEventListener(Event.COMPLETE, completeHandler);
31
 this._loader.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
32
33
 var myLoader:Loader = new Loader();
34
 myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, createCaptcha);
35
   
36
 var byteArr:ByteArray = new ByteArray();
37
 byteArr = this._loader.data;
38
39
 if(byteArr.length != 0) { myLoader.loadBytes(this._loader.data); } 
40
 else { /* SOS.alert("error"); */ }
41
 }
42
 private function createCaptcha(e:Event):void
43
 {
44
 this._captchadata = new BitmapData(175, 45, false, 0xFFFFFF); //sizes of secureimage.php ~ Line 89
45
 this._captchadata = (e.target.content).bitmapData;
46
47
 this._captcha = new Bitmap(this._captchadata, "auto", true);
48
 this._captcha.x = 920;
49
 this._captcha.y = 92;
50
 this._cont.addChild(this._captcha);
51
 this._cont.addEventListener(MouseEvent.MOUSE_DOWN , renew);
52
 this.addChildAt(this._cont,0);
53
 }
54
 private function renew(_me:MouseEvent):void
55
 {
56
 this._cont.removeChildAt(0);
57
 var url:String = "show.php?"+Math.random()*100;
58
 var urlReq:URLRequest = new URLRequest(url);
59
60
 this._loader.addEventListener(Event.COMPLETE, completeHandler);
61
 this._loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
62
 this._loader.load(new URLRequest(url));
63
64
 }
65
 }
66

I hard-coded some dimensions inside the class, and some other ugly things, so feel free to change for your needs.
But don’t forget to put the Math.random() after the URI to refresh the captcha, this can avoid caching issues.
You can see this class Working here. Click on the share Btn.

Sure, this class can be used to load nearly all types of binary image data ….

http://privatefunction.net/wp-content/plugins/sociofluid/images/digg_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/delicious_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/technorati_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/google_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/facebook_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/mixx_32.png http://privatefunction.net/wp-content/plugins/sociofluid/images/twitter_32.png
Return top

INFORMATION