Category Archives: Uncategorized

ByteArray.readUTFBytes()

Actionscript:
  1. var m:ByteArray = new ByteArray();
  2. var bytes:Array = [0x41, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20,
  3.                    0x53, 0x6E, 0x69, 0x70, 0x70, 0x65, 0x74]
  4. for (var i:int = 0; i <bytes.length; i++){
  5.     m.writeByte(bytes[i]);
  6. }
  7.  
  8. m.position = 0;
  9.  
  10. trace(m.readUTFBytes(bytes.length));

I was messing around with a hex editor today and decided to start playing with ByteArray for the first time in awhile. Just wrote this as a little warm up... Try running it to see what it traces out...

Posted in Uncategorized | Tagged , , , | 2 Comments

ActionSnippet Contest

I started ActionSnippet last year in October. Excluding the last few months I posted pretty much everyday... resulting in about 350 posts including this one. If you haven't spent time looking at some of the early posts... I recommend digging around as there are lots of very compact tips and tricks... have a look (scroll down for early posts).

For at least the next two months I'm going to post at least twice a week rather than the original every day... that said, I think it would be nice to post additional ActionScript snippets submitted by readers. This has actually been something that numerous people asked me about when the site first went online. So, if you have a snippet you'd like to submit you can simply e-mail me (bendvent [] gmail) with the subject line "AS3 Snippet". You should include your full name, link to your website and any other information you would like to be published along with your snippet.... this can include anything from links to work you've previously done... to references related to the snippet your submitting. The snippet you submit should ideally be less than 30 lines of code, but can be as long as 100 lines. This snippet submission process will go on for the next month and will end November 1st. On November 8th one of the people who submitted will be chosen as the winner and can choose from either a $300 apple gift certificate or a $300 deposit to their paypal account.

When submitting, it's important to note a few things:

If you send me a snippet that already exists on the website I'll e-mail you back and let you know that this snippet is already on the site. If you send me a snippet that doesn't make any sense, has errors etc... I may not reply at all. If you send me a snippet that I would like to include on ActionSnippet, I will e-mail you back to discuss things that we will include in the post. Only snippets that end up as blog posts on this site will be considered for judging.

Since ActionSnippet is a pretty low traffic site, I'm not expecting for there to be too many submissions, but it would be cool if people who like this site attempt to help spread the word by tweeting and blogging about this contest.

If you have any questions feel free to post comments. I have a feeling that I may need to clarify a few things about the contest.

After the contest is over I may decide to run another contest or create a snippet submission page.... my decision will be related to how well this contest goes.

Currently I'm the only judge for the contest... but there will be at least one other judge announced in the next day or two.


Updates and Contest Rules

You can submit as many snippets as you want... you aren't limited to just one... and if I like more than one of your snippets you will get multiple blog posts on the site.

Posted in Uncategorized | Tagged , , , | 11 Comments

Processing Class at FMA

This Sunday I'm doing a free one day workshop in Processing.

Processing is a gateway programming language. It helped me to ease my way into Java, C++ and OpenGL. Without Processing, learning those languages would have been much harder for me. Processing is also an amazing tool for prototyping and doing proof of concept tests.

The class itself is eleven weeks long but the first class is free. If you'd like to read more about it, or sign up for the whole eleven weeks check out this link:

Processing Class at FMA

If you want to attend the free workshop, simply post a comment and you'll be e-mailed a free pass for the class.

And if you haven't seen Processing.js yet... check it out here.

Posted in Uncategorized | 4 Comments

White Circles Black Circles

Actionscript:
  1. [SWF(backgroundColor=0xFFFFFF, width=500, height=500)]
  2.  
  3. var hsw:Number = stage.stageWidth / 2;
  4. var hsh:Number = stage.stageHeight / 2;
  5. var pointNum:int = 200;
  6. var points3D:Vector.<Number> = new Vector.<Number>();
  7. var points2D:Vector.<Number> = new Vector.<Number>();
  8. var uvts:Vector.<Number> = new Vector.<Number>();
  9. var sorted:Array = [];
  10. var thickness:Vector.<Number> = new Vector.<Number>();
  11. var radii:Vector.<Number> = new Vector.<Number>();
  12. var colors:Vector.<uint> = new Vector.<uint>();
  13.  
  14. var pnt:Point = new Point();
  15. var m:Matrix3D = new Matrix3D();
  16. var v:Vector3D = new Vector3D();
  17.  
  18. for (var i:int = 0; i<pointNum; i++){
  19.     v.x = Math.random()*1000-500;
  20.     m.identity();
  21.     m.appendRotation(Math.random()*360, Vector3D.X_AXIS);
  22.     m.appendRotation(Math.random()*360, Vector3D.Y_AXIS);
  23.     m.appendRotation(Math.random()*360, Vector3D.Z_AXIS);
  24.     v = m.transformVector(v);
  25.     points3D.push(v.x, v.y, v.z);
  26.     points2D.push(0,0);
  27.     uvts.push(0,0,0);
  28.     sorted.push({});
  29.     thickness.push(Math.random() * Math.random() * 50 + 4);
  30.     radii.push(Math.random() * 100 + 10);
  31.     colors.push([0xFFFFFF, 0x000000][int(Math.random()*2)]);
  32. }
  33. points3D.fixed = true;
  34. points2D.fixed = true;
  35. uvts.fixed = true;
  36. thickness.fixed = true;
  37. radii.fixed = true;
  38. colors.fixed = true;x
  39. var p:PerspectiveProjection = new PerspectiveProjection();
  40. var proj:Matrix3D = p.toMatrix3D();
  41. var dx:Number = 0, dy:Number = 0;
  42. addEventListener(Event.ENTER_FRAME, onLoop);
  43. function onLoop(evt:Event):void {
  44.     var i:int, j:int;
  45.     dx += (mouseX - dx) / 4;
  46.     dy += (mouseY - dy) / 4;
  47.     m.identity();
  48.     m.appendRotation(dx, Vector3D.Y_AXIS);
  49.     m.appendRotation(dy, Vector3D.X_AXIS);
  50.     m.appendTranslation(0, 0, 1000);
  51.     m.append(proj);
  52.     Utils3D.projectVectors(m, points3D, points2D, uvts);
  53.     for (i = 0, j = 0; i<points2D.length; i+=2, j++){
  54.         sorted[j].x = points2D[i] + hsw;
  55.         sorted[j].y = points2D[i + 1] + hsh;
  56.         sorted[j].z = uvts[j * 3 + 2];
  57.         sorted[j].color = colors[j];
  58.         sorted[j].radius = radii[j];
  59.         sorted[j].thickness = thickness[j];
  60.     }
  61.     sorted.sortOn("z", Array.NUMERIC);
  62.     graphics.clear();
  63.     for(i = 0; i<sorted.length; i++){
  64.         var element:Object = sorted[i];
  65.         var zpos:Number = element.z * 18000;
  66.         graphics.lineStyle(element.thickness, element.color);
  67.         graphics.drawCircle(element.x, element.y, zpos + element.radius);
  68.         graphics.endFill();
  69.     }
  70. }

Was just looking at the stills from yesterdays post and noticing how much I actually like the way they looked. Really simple, just black and white cirlces - reminded me a bit of this flash experiment by Jared Tarbell (from 2002).

So I popped the same kind of black and white circles into the z-sorting 3D snippet I've been using recently and came up with this...


Have a look at the swf...


Posted in Uncategorized | Tagged , , | Leave a comment