When I started developing in flash using the Box2d physics engine, I had this problem which held me back for a couple of hair pulling hours. So I thought, why not spare other people from this misery?
The Problem’s Symptoms
If you encountered any of these error messages when compiling a Box2d flash project:
b2World.as, Line 871 - 1046: Type was not found or was not a compile-time constant: Vector. - public function RayCastAll(point1:b2Vec2, point2:b2Vec2):Vector.
b2World.as, Line 917 - Warning: 3590: void used where a Boolean value was expected. The expression will be type coerced to Boolean. - return (m_flags & e_locked) > 0;
Input.as, Line 155 - Warning: 3590: void used where a Boolean value was expected. The expression will be type coerced to Boolean. - mouseReleased = !e.buttonDown;
Input.as, Line 189 - Warning: 3590: void used where a Boolean value was expected. The expression will be type coerced to Boolean. - return (keyState[k] > 0);
Input.as, Line 199 - Warning: 3590: void used where a Boolean value was expected. The expression will be type coerced to Boolean. - return (keyState[k] == 1);
Input.as, Line 208 - Warning: 3590: void used where a Boolean value was expected. The expression will be type coerced to Boolean. - return (keyState[k] == -1);
Input.as, Line 217 - Warning: 3590: void used where a Boolean value was expected. The expression will be type coerced to Boolean. - return (keyBuffer[i][0] == k && keyBuffer[i][1] <= t);
1046: Type was not found or was not a compile-time constant: b2PolygonDef. - var the_box:b2PolygonDef;
1067: Implicit coercion of a value of type Box2D.Collision:b2AABB to an unrelated type Box2D.Common.Math:b2Vec2. - the_world=new b2World(environment,gravity,true);
1137: Incorrect number of arguments. Expected no more than 2. - the_world=new b2World(environment,gravity,true);
1178: Attempted access of inaccessible property m_sprite through a reference with static type Box2D.Dynamics:b2DebugDraw. - debug_draw.m_sprite=debug_sprite;
1178: Attempted access of inaccessible property m_drawScale through a reference with static type Box2D.Dynamics:b2DebugDraw. - debug_draw.m_drawScale=30;
1178: Attempted access of inaccessible property m_fillAlpha through a reference with static type Box2D.Dynamics:b2DebugDraw. - debug_draw.m_fillAlpha=0.5;
1178: Attempted access of inaccessible property m_lineThickness through a reference with static type Box2D.Dynamics:b2DebugDraw. - debug_draw.m_lineThickness=1;
1178: Attempted access of inaccessible property m_drawFlags through a reference with static type Box2D.Dynamics:b2DebugDraw. - debug_draw.m_drawFlags=b2DebugDraw.e_shapeBit;
1180: Call to a possibly undefined method b2PolygonDef. - the_box = new b2PolygonDef();
1061: Call to a possibly undefined method CreateShape through a reference with static type Box2D.Dynamics:b2Body. - final_body.CreateShape(the_box);
1061: Call to a possibly undefined method SetMassFromShapes through a reference with static type Box2D.Dynamics:b2Body. - final_body.SetMassFromShapes();
1046: Type was not found or was not a compile-time constant: b2PolygonDef. - var the_box:b2PolygonDef;
1180: Call to a possibly undefined method b2PolygonDef. - final_body.CreateShape(the_box);
1061: Call to a possibly undefined method SetMassFromShapes through a reference with static type Box2D.Dynamics:b2Body. - final_body.SetMassFromShapes();
1136: Incorrect number of arguments. Expected 3. - the_world.Step(1/30, 10);
Warning: 3590: Box2D.Common.Math:b2Vec2 used where a Boolean value was expected. The expression will be type coerced to Boolean. - the_world=new b2World(environment,gravity,true);
1046: Type was not found or was not a compile-time constant: b2World. - public var the_world:b2World;
1046: Type was not found or was not a compile-time constant: b2AABB. - var environment:b2AABB = new b2AABB();
1046: Type was not found or was not a compile-time constant: b2Vec2. - var gravity:b2Vec2=new b2Vec2(0.0,10.0);
1046: Type was not found or was not a compile-time constant: b2DebugDraw. - var debug_draw:b2DebugDraw = new b2DebugDraw();
1046: Type was not found or was not a compile-time constant: b2Body. - var final_body:b2Body;
1046: Type was not found or was not a compile-time constant: b2BodyDef. - var the_body:b2BodyDef;
1046: Type was not found or was not a compile-time constant: b2PolygonDef. - var the_box:b2PolygonDef;
1180: Call to a possibly undefined method b2AABB. - var environment:b2AABB = new b2AABB();
1180: Call to a possibly undefined method b2Vec2. - var gravity:b2Vec2=new b2Vec2(0.0,10.0);
1180: Call to a possibly undefined method b2World. - the_world=new b2World(environment,gravity,true);
1180: Call to a possibly undefined method b2DebugDraw. - var debug_draw:b2DebugDraw = new b2DebugDraw();
1120: Access of undefined property b2DebugDraw. - debug_draw.m_drawFlags=b2DebugDraw.e_shapeBit;
1180: Call to a possibly undefined method b2BodyDef. - the_body = new b2BodyDef();
1180: Call to a possibly undefined method b2PolygonDef. - the_box = new b2PolygonDef();
1046: Type was not found or was not a compile-time constant: b2Body. - var final_body:b2Body;
1046: Type was not found or was not a compile-time constant: b2BodyDef. - var the_body:b2BodyDef;
1046: Type was not found or was not a compile-time constant: b2PolygonDef. - var the_box:b2PolygonDef;
1180: Call to a possibly undefined method b2BodyDef. - the_body = new b2BodyDef();
1180: Call to a possibly undefined method b2PolygonDef. - the_box = new b2PolygonDef();
1172: Definition Box2D.Dynamics could not be found. - import Box2D.Dynamics.*;
1172: Definition Box2D.Collision could not be found. - import Box2D.Collision.*;
1172: Definition Box2D.Collision.Shapes could not be found. - import Box2D.Collision.Shapes.*;
1172: Definition Box2D.Common.Math could not be found. - import Box2D.Common.Math.*;
I have the solution.
Possible Causes
There are two main causes for these type of errors:
- The Box2d code you are compiling doesn't match the Box2d source files' version.
- Flash can not locate the Box2d engine source files.
Version Difference
Personally, I first encountered the first cause. As it seems, when the Box2d guys updated their SVN and downloads for the latest version (for the time writing this post: 2.1 alpha aka 2.1a), they forgot to also update their code samples. So if one downloads the latest version and tries to compile the example projects, it simply won't work. Instead, flash will throw some of the errors listed above.
In addition, all of the online resources and tutorials regarding Box2D don't work with the latest Box2D version. I have yet to find an article or a code sample that works flawlessly with the latest version. They really rewrote major parts of the engine thus making lots of code (if not all) incompatible.
Missing Box2D files
The second cause is also very common. When compiling any project which uses the Box2d physics engine, Abobe must be able to find the needed Box2d source files. Adobe Flash looks for the files in the projects directory (is our case, for a Box2D subdirectory), and at the locations which one can specify in the preferences menu.
The Solutions
These solutions have solved my problems. If these won't help you, or if you have a better solution that you'd like to suggest - comment below.
Version Difference
As I've mentioned before, the examples in the latest Box2D download don't match the correct version and almost any code sample you will find online won't work with the latest version of Box2D.
Visit their full download page which contains all previous versions and download version 2.0.2. All the examples work great in this package. And any other code should also work using this version.
Missing Box2D files
Many times, Adobe Flash (also Flash Develop and any other Flash IDE) won't find the correct Box2D directory to use. As a result it will throw those errors.
To fix this, you have two options:
- You can simply copy the correct Box2D source folder (a folder named
Box2D) to the directory of your project. For instance, if your project lies underC:\projects\box2d-demo\demo.fla, you will need to copy the Box2D folder there. In the end the Box2D folder should lie atC:\projects\box2d-demo\Box2D. - The second option is to inform your IDE about the location of your Box2D folder. I use this option and I store my Box2D directory at
C:\Documents and Settings\Oren Yomtov\My Documents\FlashUtilities\Box2D.To inform your IDE, follow the following steps:
In Adobe Flash:
- Open your project in Adobe Flash.
- Navigate to "Edit->Preferences...".
- Click the "ActionScript" tab/category.
- Click the "ActionScript 3.0 Settings..." button.
- Click the "Browser To Path" (folder/cross icon) button under "Source path:".
- Browse to the folder which contains the Box2D folder and click "OK".
- Click "OK" twice to save the changes.
In Flash Develop (If you use it):
- Open Flash Develop
- Navigate to "Project->Settings..."
- Click the "Classpaths" tab.
- Click the "Add Classpath..." button.
- Browse to the folder which contains the Box2D folder and click "OK".
- Click "OK" to save the changes.
NOTE: If you use both, you will need to configure both.
Do not browse directly to the Box2D folder. Instead, browse to it's parent folder.
Now recompile your code and it should all work.
By the way, if you are looking for video tutorials on the Box2D engine - check out Todd's great videos. They are very detailed and fun. Good luck.
Last month I participated in two amazing events. The first one is The Big Geek and is considerably similar to the second event called Startup Weekend. They both took place in Israel.
The Big Geek II
Startupseeds

This event was organized by StartupSeeds, a non-profit organisation encouraging teen Israeli entrepreneurs to make their first steps in the entrepreneurship world. Whether it’s by giving them a place to talk about technology, or by conducting monthly meetings with the most interesting lectures (for free!). StartupSeeds even assists young innovative kids with starting their own startups by providing them financial help and the best mentors available. The online forum and meetings created a large and friendly community for the Israeli teenager who breaths technology and internet.
What’s the event about?
Sixteen kids (Ages 14-18), divided into four “teams”, worked 24 hours non-stop on their unique idea for a startup. Each team raised a fully working service within those 24 hours (!). While the projects are not breath-taking nor unbelievable, they are still awesome considering the time spent working on them. Actually, they’re awesome not matter what.

The project that my team and I developed is FixedInch. It’s a free online service for displaying objects in their real size over any screen in the world. We have discussed the possibility to continue working on it, and we most likely will, in the near future.
What else can I say? It was an awesome experience that I will never forget. It was 24 hours of fun and jokes, some of could not be told anywhere else like (via @TalDromi):
“Let’s use JSON for this”
“Who’s this Jason you are talking about?”
“XML’s brother!”
Startup Weekend Israel 2009
This is a world-wide known event, which started in 2007. Since then it took place in over 50 cities and growing (!). This is kind of a grown-up version of the Big Geek.
During the first day, 140 Israeli entrepreneurs pitched 50 unique ideas which turned into thirteen motivated teams. Each team consisted of about 4-8 people who designed and developed their idea for three days. The second day was all about work and food (lots of it!). On the third day of the event, the teams finished their work and presented their project.

My team and I worked on Frayer Meter – an online free service that suggests the most economical cellular plan according to one’s needs. While it’s not fully functional, we plan to continue working on it as we believe in it’s potential.
NOTE: If you don’t know Hebrew, feel free to use Google Translate when visiting links from this post.
Lately a fellow web developer of mine asked me why can’t he manage to save the current time in a MySQL table. The problem was that he didn’t understand how the PHP timing mechanism works. That’s why I decided to write this article.
time() and date()
time()
The time() function receives no parameters and returns the current time measured in the number of seconds since January 1 1970 00:00:00 GMT.
This may sound a bit weird but I find it to be clever.
Because one doesn’t want to display dates and times in PHP as a very long number (e.g. “The current time is 1256702873″), the date() function was created.
date()
The date() function returns a string formatted according to the given format parameter.
The function is documented as follows:
string date ( string $format [, int $timestamp ] )
While I’d prefer to think of it as
string date ( string $format , int $timestamp=time())
Because if you don’t pass the second parameter, it uses the time() function instead.
Lets see a couple of examples:
<?php
// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the
// Mountain Standard Time (MST) Time Zone
$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
$today = date("m.d.y"); // 03.10.01
$today = date("j, n, Y"); // 10, 3, 2001
$today = date("Ymd"); // 20010310
$today = date('h-i-s, j-m-y, it is w Day'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 10th day.
$today = date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month
$today = date("H:i:s"); // 17:16:18
?>
I don’t want to get into the format parameter, but you can read about it at the PHP manual.
Saving the time in a MySQL Database
The wrong way
My friend was using some sort of a special “date”/”time”/”timestamp”/”datetime” column type because he didn’t know what he was getting from the time() function.
This is not the way to store the result from time(). While it may be useful in certain circumstances, I’d rather save the number of seconds since January 1 1970 00:00:00 GMT for later easier manipulation with PHP.
The right way
All you need to do is use a simple INT or BIGINT column type to store what you get from your time() call and in order to display it, use the date() function, passing it as the second parameter.
A theme consists of many files, this can get very confusing very fast. What files are needed? What files runs when and why? Here are the explanations and tips about WordPress template files.
First things first, what is a template exactly? A template is a PHP file that is a part of a theme. For example, there is a template for displaying the home page, one for displaying pages and another one for displaying posts.
What Are The Existing WordPress Tempaltes?
Here is a list of the existing WordPress templates that can be used in themes:
- index.php – The master template. If a certain template file does is not found, this one is being used.
- home.php – Displays the home page.
- page.php – Displays page’s page (It displays my contact page).
- single.php – Displays the post’s page (This is what you are now viewing if you are reading this here).
- author.php – Displays the author page. This is not such a common template as most themes don’t use author pages.
- tag.php – Displays the posts which have a specific tag. (e.g. FTP)
- category.php – Displays posts from a specific category. (e.g. WordPress)
- date.php – Displays posts from a specific time range.
- archive.php – Used if tag.php,category.php or date.php is not found.
- search.php – Displays search results. (e.g. How To)
- 404.php – When WordPress sends a 404 header. (When it cant find something)
- image.php,video.php,audio.php,application.php or any other first part of the attachment’s MIME type – Attachment.
- attachment.php – If one of the last templates (image.php…) are not found.
Here is a very useful image provided by WordPress Codex (click to enlarge):
Custom Templates
There are two main types of custom WordPress templates.
The first one are templates that WordPress looks for automatically, and if one is found it will be used. What the heck am I talking about?
If you have a category called “News” with the ID of 512 and you want the archive page of that category to have it’s own unique template you can create a new template file called category-512.php in the theme’s folder. And WordPress will use it.
This is the list of custom wordpress templates you can use:
- category-id.php
- tag-slug.php
- pagename.php
- firstpartoftheattachmentsMIMEtype.php

Now for the second type of WordPress custom templates.
Let’s say you have more then one page* you want to be displayed in a different way then the others. How do you do that?
Create a new file called whatever.php at your theme’s folder and inside write whatever you want instead of single.php or index.php (depending what displays the single posts at your theme).
Add this comment to the top of the file:
<?php
/*
Template Name: The Whatever Template Yo
*/
?>
(Of course change The Whatever Template Yo to the new template’s name)
Now edit (or create) the pages which you want to use this template and in the right side pick the desired template from the drop down menu. Just like in the screenshot at the right side.
*If you want to do this for posts rather then pages then you will find the Custom Post Template plugin very useful.
Any questions/corrections? Comments are always welcome.
I have received a request from someone that wants even more from my WordPress Custom Fields Plugin. He has a category called “videos” which has posts with YouTube videos embedded with some plugin. He wants to put the videos thumbnail as the post’s thumbnail.
First, how is the video embedded in the post? It uses the following syntax:
[youtube $video_key]
Now you can embed it like you would normally do.
Second, how do we get the thumbnail itself after we extracted the video key? We build the image’s URL with the following syntax:
http://i2.ytimg.com/vi/$video_key/default.jpg
Now, how do we put all of this together into a plugin that inserts the thumbnails?
You don’t have to because I have already done it for you.
- Visit the plugin page of YouTube Thumbnailer
- Download the plugin here
- Unzip it’s contents
- Upload the folder you unzipped to
/wp-content/plugins/using your favorite FTP client. - Go to your admin panel and activate the plugin called “Youtube Thumbnailer”
This plugin runs through the posts in your blog and if it finds a YouTube video embedded in a post it sets the thumbnail to be the video’s thumbnail.
That’s it, have fun playing with the configuration.
If you encounter any issues please comment/contact me.
I want to thank everyone who sent feedback and feature requests for the post editor buttons plugin.
Because of you I have released 3 more version of mainly bug fixes to the plugin.
The feedback was send through comments on the blog and email messages to me, if you have something on your mind, do not hesitate.
Now you can download and use version 1.3 that works perfect.
By the way if you have an idea for a brand new plugin – contact me :)
Post Editor Buttons?
This plugins allows you to add your own buttons to the post edtor’s toolbar.
I’m talking about the buttons that you see above your content text area when editing posts (b,i,link,img,ul,li).
For example you can add a “h3″ button to make subheaders in your post.
There are virtually endless buttons you can add.
Screenshots
Here is the plugins interface:

This is the output of the above settings:

Download
You can visit the plugin’s WordPress.org page, download the plugin right away and upload it into your plugins directory.
Feedback
Comment whatever is on your mind.
The new version of Mass Custom Fields Manager is out!
Why do you need it? For example if you have custom fields that old plugins left of your posts and you want to get rid of them you can now do it with a click of a mouse. There are virtually endless occasions where this plugin can save you valuable time and effort.
I added new features that you asked for, fixed some minor bugs and did some code optimization.
If you encounter any bugs or have an idea on how to improve the plugin then I would love to hear it from you.
The second WordPress 2.8 beta is now live for download.
You can download WordPress 2.8 beta 2 and see the list of changes on the WordPress.org development blog.
This is mainly for people who want to contribute to WordPress in another fashion by downloading the beta, using it and reporting bugs. I took a look at the list for you and there is really nothing particularly interesting, just some plain bugs & issues. I also found a cool view on the bugs, one that lets you see the changes in the files themselves.
What about you guys, Did you try the 2.8 WP beta?

WordPress developers at WordPress.org announced the release of the Wordpress 2.8 beta version for the open public. They also stated the main features and updates such as:
- New Theme Installer routines
- Improved Widget user interface
- Allow editing of all plugin files
- “Choose a city in the same timezone as you” for Timezone in Administration > Settings > General
- Remove My Hacks option from Administration > Settings > Miscellaneous
- Hide email addresses from low privilege users on Administration > Comments
- Allow case-insensitive logins
- Add password strength meter to Add User and Edit User
- Drop post_category column from wp_posts table, and link_category column from wp_links schemas
- Add hooks for the Users, Categories, Link Categories, Tags and Comments table columns
- Put page title before blog name in admin title
- Fixes to query_posts (obey post_type, drop orderby=category, use group by for meta key queries, remove meta_value from selected fields)
- Add hook for adding info to plugin update message
- Add a function to output a generic widget anywhere in a template
- New Widgets API
- Allow menu reordering via plugin
I read the whole list and pointed the things that I think are most important here.
WordPress 2.8 Beta 1 Download Link
You can get the beta version and test it at WordPress.org.


