IconUtilityPlus - use DisplayObjects as flex icons

recently i needed a way to generate small preview-thumbs and put them on flex' Buttons - as it turned out, it isn't that easy to use dynamic content as icons at all.
after some while i found a nice way to put dynamically loaded images in icons: ben stucki's IconUtility.

i took his class and kicked it up a notch. now it's able to take any DisplayObject as a source and lets you use it as an icon for flex components:

  1. var sprite:Sprite = new Sprite();
  2. sprite.graphics.beginFill(0xff0000, 0.5);
  3. sprite.graphics.drawCircle(0, 0, 15);
  5. var button:Button = new Button();
  6. button.setStyle("icon", IconUtilityPlus.getClass(button, sprite));

of course it works in MXML, too:

  1. <mx:Button id="button" icon="{IconUtilityPlus.getClass(button, sprite)}"/>

i've also added a third parameter for animated DisplayObjects like Video or MovieClip - added this just for fun, it will definitely cost some performance to display animated stuff and may be buggy.

thanks again to ben for the previous work, it really is some smart way to bypass adobe's way of only using classes :)

here it is: IconUtilityPlus.as

edit: fixed drawing method for DisplayObjects with offsets <0

Posted in Uncategorized | 5 Comments

communicaty arbitrary data via rtfmp (late sources)

here are the sources. just for the sakes of a new blog post.. ;)

i wish i had the time to play around with it some more by now - months have passed! :/

remember to get a status account and put your id in the sources - otherwise it won't work. have fun.

Posted in Uncategorized | Leave a comment

communicating arbitrary data via rtfmp (pt. 2)

sending custom classes via rtmfp? well, let's try :D

according to the example of the first part of this article we would now like to pass our receiverFunction() an instance of SomeObject instead of a String.


here's the initial class SomeObject which we'll try to send from one peer to another:

  1. package 
  2. {
  3.     public class SomeObject
  4.     {
  5.         private var i:int;
  7.         public function SomeObject(value:int)
  8.         {
  9.             i = value;
  10.         }
  12.         public function get value():int { return i; }
  13.     }
  14. }

of course we have to adjust our peers as well:

sending peer:

  1. var netStream:NetStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
  2. var sendTimer:Timer = new Timer(1000);
  3. sendTimer.addEventListener(TimerEvent.TIMER, senderFunction);
  4. ...
  5. public function senderFunction(te:TimerEvent):void
  6. {
  7.     var someObject:SomeObject = new SomeObject(Math.random()*303);
  8.     netStream.send(”receiverFunction”, someObject);
  9. }

the timer-function sends an instance of SomeObject with a random value every second through the stream.

receiving peer:

  1. var netStream:NetStream = new NetStream(nc, id_of_sending_peer);
  2. var clientObj:Object = new Object();
  3. clientObj.receiverFunction = function(arg1:SomeObject):void{ trace(arg1.value); }
  4. netStream.client = clientObj;

we want the receiver to accept the object and trace its value in the console.

unfortunately the application in its current state would throw an AsyncErrorEvent caused by the fact that the receiver is not able to read a SomeObject from the stream, it only sees a strange Object of unknown type:
Type Coercion failed: cannot convert Object@3019da9 to SomeObject.

maybe you know this error from experiments with ByteArray. in fact there is quite a sum of analogies between the ByteArray-methods writeObject() and readObject() and the exchange of data via NetStream.send() - that's because both are data streams.
so we have to make our SomeObject serializable, means: if we can write it to a ByteArray and read back again, we're halfway there.

i think i'll put a jump here, because this may be getting a longer article :)
more »

Posted in Actionscript, Networking | 9 Comments

communicating arbitrary data via rtfmp (pt. 1)

hi there and a happy new one (can you still say that on january 7th?).

since i am supposed to work on my bachelor thesis it got quiet around here.
but when i read about the new stratus service a few days ago i couldn't wait to get my hands on it. for those who haven't heard of it: it's a service which provides information to the flash player/air instance to communicate peer-to-peer to another remote instance. before this stratus beta started there was no way of using the new rtmfp (an udp-based network protocol which came with fp10) at all.

after creating a small one-way microphone-chat i wondered how to exchange arbitrary data between the peers. the adobe stratus site reads about the use of rtmfp: "A video chat application, Multi-player game, Voice Over IP" - ok, so while the first and last of that list is in fact quite the same (NetStream.attachCamera() and attachAudio()) and greatly covered by jozsef vass' article "Stratus service for developing end-to-end applications using RTMFP in Flash Player",  there are no resources about how to exchange data other than video and audio. or are there?!

in the fp10 api i stumbled upon NetStream.send() which was previously used to communicate with the FMS only, i guess. so like with ExternalInterface you can call functions outside of flash's sandbox: so not javascript this time, but actionscript on other peers. (:
to be more specific: you call functions on the NetStream.client which is of type Object - so you can put there whatever you want. to a function of this client-object you can pass as many arguments as you like, as long as they are of native types.

you'll find a short example after the jump:

more »

Posted in Actionscript, Networking | 4 Comments


actually sound pitching was the first thing i did as soon as the flash 10 beta came out. now that there were some changes in the sound api i wrote it new from scratch.

the finetuning took a while so that there are no more hickups and noises when changing the pitch fluently as you can hear in the provided example.
well, at least i think so. it's only been tested with my local beta standalone player yet. the release version is out since yesterday or so and the bad news already spread - there are again changes to the sound api causing huge latencies depending on your operating system and your hardware apparently.

whatever. be sure to get the fresh flash 10 player - no more beta :D - and check out the little turntable.

the new SoundPitch class is to really easy-to-use: it extends the regular Sound class and the access works just the same:

  • load a sound via .load(myURLRequest) or .load(mySoundObject)
  • play the sound via .play()
  • pitch the sound via .pitch = 0.7
  • you can also change the buffer's length via .bufferLength = 6

get it here! (going to clean the code up soon ;)

Posted in Actionscript | 12 Comments

ripple the shipple

there has been some transformation to the original sphere again. the goal was to maintain the 3d-ish effect of the sphere unlike in the previous flowery example.

just play around a bit with it. for instance, you can change the position of the point the ripples "look at" and of course the position of the light source.
if your eye isn't too critical - regarding the straight circle outline shape of the whole thing - it's pretty neat i think :)

and again i encourage you to install the newest beta player of flash 10.
i thought about adding another link to a projector-executable because the flash 10 player plugin hasn't really spread that widely yet. on the other hand it is kind of strange to download a 2.x mb executable just to see a effect designed to run in a browser ;D

Posted in Uncategorized | 2 Comments

lets bend the sphere some more

a logical step was to transform the mathematically described surface of the sphere as you can see on the right. in this example - which i like to call flowery sphere - there is a sum of parameters you can play with. again, you'll need flash 10!

the elegance of a sphere is that it looks exactly the same from whereever you look. now with the transformed surface this effect is gone - it looks alot flatter than the spheres. also it wouldn't make sense to have a few of them floating around in space as they do in the previous post.

maybe in a later post i'll go into detail of how it all works. but i have another approach in the oven i'd like to finish first :)

Posted in Actionscript, Pixel Bender | Leave a comment

pixelbent spheres

basing on some experiments some time ago with pixel bender kernels i was able to render a few spheres with local illumination for one light source based on phong:

  • ambient illumination (as a substitute for all indirect light bouncing around in the scene)
  • diffuse illumination (lets parts of the surface pointing to the light source be lighter than those pointing somewhere else)
  • specular illumination (adds highlights - you can simulate different materials with that by playing around with the parameters)

that's phong. its all that gets calculated for each pixel. and that's a lot.. you can see that pretty soon as you add spheres.
even with a multicore cpu (which is finally supported by flash player 10, yay!) you're happy to reach a bit over 30 spheres without heavy frame drops.

well. of course a shader isnt the best way to render a sphere because you could do lots of stuff iteratively using the previous calculations. that's a thing you cannot do with pixel bender at all - you don't know in which order the shader runs through the image.
but that is another topic ;)

the current release of flash 10 is needed for this and further examples!

Posted in Actionscript, Pixel Bender | Leave a comment

opening sequence

greetings fellow flash(develop)ers!

finally i got myself to posting a first entry on my blok.

not only that its the first post here - it's also the first content on krisrok.de! i hope you enjoy my little experiments and stuff which will pop up here soon.

ah i should drop some lines to introduce myself to you: currently i’m a 24 year old flash developer working for a middle sized, cozy agency in duesseldorf, germany. my main interests are the features of the upcoming flash cs4, especially pixel bender at the moment. so much for now - you’ll read more about that soon enough ;)

Posted in General | 1 Comment