Code In Vain

Daniel Cohen talks shop

Follow me on TwitterRSS Feeds

  • Home
  • About Me
  • בלוג עברי
  • Virtual Remote
  • DNA Studio

Working With Large Arrays in Action Script

Jul 26th

Posted by daniel in dev

No comments

While working on partly connected system using flex technology I figured out quick enough that working with large data sets (thousands of records) is not applicable. Especially because i held a number of those sets which I needed to  cross reference in number of occasions.

My solution was to create an indexed collection which i can benefit both worlds of Dictionary and ArrayCollection , with that in mind I designed and implemented the IndexedArrayCollection.

The collection extends ArrayCollection and adds the capability of indexing a single member of an object in the collection (I assume that each element is an object).

IndexArrayCollection constructor receives two arguments first is a source array and second is the index field name (attribute name).

as3, dev, flex, pattern, performance

Pong Applied Box2DFlex Physics Engine

Jul 22nd

Posted by daniel in dev

1 comment

I decided to learn by example and assigned myself the goal of building pong in box2d.

box2d is an overkill for pong , but what do you know, it’s damn easy.

the gist of it is :

  • layout
  • world setup
  • event handling

Full source code hosted in github Pong in Box2DFlex.

The layout

a SkinnablePhysicsContainer holding two border containers (named p1 and p2) which are the player bars and corelating p1Goal and p2Goal which will act as hit area for the ball graphics element (Ellipse).

Setting Up the World

when the application loads it maps all elements in the physics container to box2d bodies , in woldSetup method i specified different mapping types to components

The key thing you need to know is that you want  p1, p2 and the goals controls to be kinematic bodies so

  • they are not affected by collations and
  • they do not collide with each other
  • they affect dynamic bodies colliding into them

and an event handler onBodiesContact that triggers when two bodies collide .

Event Hadnling

onBodiesContact is triggered each time two bodies collide indie it i do a simple test to see which to bodies collided and triggers the respective indicator.

world_mouseMoveHandler is handling the translation of mouse position and movement of p2

var p2b:b2Body = worldUIContainer.getComponentBody(p2);
p2b.SetPosition(new b2Vec2(p2b.GetPosition().x,worldUIContainer.worldDef.meter(nextPos)));
box2d, Box2DFlex, dev, flex, game, open source, TECH

Box2D Flex Complex Shapes Mapping

Jul 15th

Posted by daniel in dev

No comments

One of the drawbacks in box2d is that it’s not supporting concave polygon shapes .

for that box2d flex employs several algorithms and converts a complex shape to a set of polygons (I took the idea from 3d modeling)

at this point i would like to give credits to

  • sakri.net for he’s shape outline algorithm
  • makc.coverthesky.com for he’s polygon2d

both state that their algorithms are far from perfect but for a v0.2 it’s a good start.

in this case I’ll start from the demo and then go into the code so see how the doll bellow is segmented to several triangles.

first thing is to understand how what the doll constructs of , in our case it’s a graphics

our object can be comprised of anything , graphic shapes , ui controls, images etc’ it has only one caveat - It’s edges must be transparent .

The next thing it to take a look at our physics container

you can see that autoStartPhysicsEngine is set to false. By default SkinnablePhysicsContainer maps all it’s flex objects to box2d shapes on creation, this time we want to interfere before hand and give the engine a different directive to try and map the shape not by it’s boundingBox but by it’s actual edges.

This is done by actionscript code, in which we tell our physics container to parse complex shape and pass it with the shape id and a parsing object, afterwards we call the physics engine to start.

you can see the the shape parser receives an argument specifying the quality of it’s mapping , this is done for performance  improvement but might impair edges fidelity.

actionscript, box2d, Box2DFlex, dev, flex

Simple Box2D Flex Example

Jul 13th

Posted by daniel in dev

No comments

following my previous post announcing Box2D Flex framework i want to share some techniques via examples on how to use the library.

First thing we create add a SkinableContentContainer to and drop some contorls inside it

This, still, does not do anything fancy it just initializes box2d and registers & measures all controls inside our physics container.

next step we add some bindable controls that will change our physics gravity and debug

and the bindable properties to our physics container

now we can play with the gravity sliders and see flex controls bounce around

as3, box2d, Box2DFlex, dev, flex, mxml

Announcing Box2D Flex framework

Jul 11th

Posted by daniel in dev

1 comment

Prefix

In a previous post demonstrating box2d integration with flex I made a promise (mainly to myself) to share the demo code. When I started to review with sharing in mind it looked cumbersome and overly verbose. So I started cranking on it fixing and straightening the code & architecture and step by step I realized that I’m creating a small Integration layer rather then a POC.

Announcing Box2DFlex

Box2DFlex framework allows you easely integrate box2d into flex framework using mxml. The framewok helps easy integration with flex and exposes box2d world for advanced manipulation.
  • extends SkinnableContainer uses flex component lifecycle model
  • uses regular MXML and AS flex components
  • supports complex shaped flex components (convex and concave) conversion to b2d shapes.
  • allows multiple worlds side by side

Getting Started

In order to play with Box2dFlex you will need flash builder 4 and Box2DFlex source which is hosted on GitHub.

and in four simple steps you should

  1. download the source code
  2. inport the Box2DFlex and Demos  projects into flash builder 4
  3. compile
  4. Play with the eamples in Box2Demos project

Building Your Own b2d World

  1. download the framework
  2. create a new project
  3. add refrence to <Box2DFlex dir>/Box2dFlexLib/bin/Box2DFlexLib.swc
  4. in your MXML add a new SkinnablePhysicsContainer
  5. set the container’s yGravity property to 10 and autoStartPhysicsEngine to true (yGravity=”10 autoStartPhysicsEngine=”true”)
  6. if you want your world to contains walls use setBoundries=”true” attribute
  7. place a button inside SkinnablePhysicsContainer and set it’s properties (width / height / label)
  8. run the project
box2d, Box2DFlex, dev, flash, flex, framework, open source
dashboard-clocks

Timezone shift in bootcamp

Jul 5th

Posted by daniel in technology

No comments

Another short one , each time i open my bootcamp or VM (parallels or fusions) i get different timezone for windows and osx.
both are configured correctly connected to the internet and updated from ntp server.

But the windows machine is persistently offsets by two hours. After some hunting around and some trial and error I found that the best and quickest solution is adding a new registry key to HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\ named RealTimeIsUniversal typed REG_DWORD and set it’svalue to 1


you can also patch your registry by downloading bootcamp clock registry update and running it on your windows machine.

mac, osx, pc, registry, timezone, tip, windows

Battling with Mac & PC in a local network

Jul 1st

Posted by daniel in technology

No comments

That’s a short one , I was banging my head for the last few months with a problem @ my home network.

I have a few computers all of which are connected via a router  and all see each other perfectly and can be accessed via IP or computer name.

All except one PC and Mac  which refused to see each other by computer name but could be accessed by IP.  But today I finally managed, after comparing the installed software on two PC’s I decided to try and uninstall Bonjour services from my PC to see if it impairs the connection , and luckily it did.

So if it happens to you  remove Bonjour services from PC

bonjour, mac, pc, TECH, tips, wins

Mid 2010 Podcast List

Jun 30th

Posted by daniel in Kaizen

No comments

it’s time to update my podcast list some shows are RIP and some new came to light. so without further ado my mid 2010 podcast list .

This time i grouped them by interest . some have fixed amount of episodes and some reoccur weekly . there are some hebrew podcasts in the list as well , I left the name and notes in hebrew.

.NET

Hanselminutes - “is a weekly audio talk show with noted web developer and technologist Scott Hanselman. Scott discusses utilities and tools, gives practical how-to advice, and discusses ASP.NET or Windows issues and workarounds.”

.NET Rocks! -” is a weekly talk show for anyone interested in programming on the Microsoft .NET platform. The shows range from introductory information to hardcore geekiness.”

Deep Fried Bytes – “The show discusses a wide range of topics including application development, operating systems and technology in general. Anything is fair game if it plugs into the wall or takes a battery.”  they are .NET centric and focus on mainstream development.

Alt.NET

i’m not sure if Alt.NET is the correct way to call the following section maybe .net with balls is more at it ….. they push the envelope

Herding Code – “Herding Code is a weekly podcast with K. Scott Allen, Kevin Dente, Scott Koon, and Jon Galloway.”  it’s the show with most hosts at once i hear but what can I say when it works it just works.

The Thirsty Developer –  “A podcast with Microsoft Developer Evangelist, Dave Bost and Clark Sell”  They bring top guests and talk about interesting topics.

Flex / AS3

The Flex Show – Everything Flex and AS3 sadly that’s the only one I found …

Open source  / Versatile technology

The Changelog – very new very cool show about open source , I hope it will last.
Software Engineering Radio – “Software Engineering Radio is a podcast targeted at the professional software developer. The goal is to be a lasting educational resource, not a newscast”
Hacker Medley – ” is a short podcast for curious hackers. Our goal is to talk about the cool things we’ve learned that we love explaining to our friends.”

WebDevRadio.com – web development podcast – “News, views and issues for the web developer”

רברס עם פלטפורמה

Tech  / inspiration

WNYC’s Radiolab – if nothing else at least you owe it to yourself to subscribe to this one.
עושים היסטוריה! עם רן לוי Making History! with Ran

Business developement

Startups For the Rest of Us – about building small ventures - “the podcast that helps developers be awesome at launching software products”
Harvard Business IdeaCast – “features breakthrough ideas and commentary from the leading thinkers in business and management”
כלכלת מוצרי מידע (ספר קולי) – ספר שמלווה קורס של האוניברסיטה הפתוחה אפשר שווה לכל מי שרוצה לבנות ולתמחר תוכנה
התנהגות ארגונית (ספר קולי) -ספר שמלווה קורס של האוניברסיטה הפתוחה אם אתה עובד באירגון גדול או רוצה להשתלב באחד

Usability

The User @ the Center of it All
Engineering and Computer Science
Human-Computer Interaction Seminar

education, Podcast list, resources, TECH

Flex 3 hebrew textbox

Jun 29th

Posted by daniel in dev

No comments

following my last post on flex3 RTL label , next challenge was input text with RTL support , in that case I decided to cheat and use html input overlying flex.

Not so elegant solution, but a solution non the less. the trick is to pass the flex component coordinate and position the HTML input accordingly , and on the HTML side handle keyboard and mouse event to let the flex developer feel @ home with regular focus and key press events.

Add the following MXML component to your flex project

Add the following code to your html page

as3, dev, flex, flex3, hack, html, input, javascript, RTL, textfield

Flex 3 label RTL support

Jun 22nd

Posted by daniel in dev

2 comments

If you know or not , I’m leaving and working in Israel, where we have the most annoying text rendering issues.

we write in right to left order – that means  in the opposite direction of most languages. Letters and words are left to right, though  numbers and other symbols remain right to left.

Through the years I’ve seen (and even wrote) noumerous attempts to build an AS class that will provide this functionality to flash, all of them suffered from quirks and different edge cases.

About a year a go Adobe published a new text rendering engine (TLF) which wasn’t integrated into Flex3 framework , and though flex4 includes the new TLF some still need to work with the 3.x framework so here is a simple example of implementing true RTL label in flex 3 note that you need to download and install Text Layout Framework on your development machine in order to compile the code.

actionscript, bidi, dev, flex3, RTL, text layout framework
123»
  • Archives

    • July 2010
    • June 2010
    • April 2010
    • November 2009
    • October 2009
    • September 2009
    • August 2009
    • July 2009
    • June 2009
  • Tags

    actionscript air2 as3 bidi box2d Box2DFlex community server crosspost demo dev education firefox flash 10.1 flex flex3 form hack html input iphone iptv javascript mac multitouch NDS objective c open source pc physics plugin Podcast list promotion resources review RTL summary TECH textfield text layout framework thanks tips vain wordpress xmlrpc xpostcs
  • What I'm Doing...

    • למה ניהול סיכונים לא מעניין אף אחד http://icio.us/dnhvns 4 days ago
    • working @ home http://icio.us/qto5ar 1 week ago
    • sketching interactive ui http://icio.us/3mz0d4 1 week ago
    • More updates...

  • View Daniel Cohen's profile on LinkedIn
  • Friends

    • Alex Trost
    • Amir Harel
    • Eran Mahalu
    • Lior Boord
    • Oded Eliashiv
    • Ruben Rosh
    • Shahar Shelly
    • Yuval Eshel
Copyright © 2010 Code In Vain
RSS Feeds Top