Mysterious class World in Flash CS5
Create a new FLA file in Flash Professional CS5 and write the following frame action:
var test:World = new World();
[Test Movie] generates the compile error #1136:
Incorrect number of arguments. Expected 2.
I have never defined the class World but tried to solve the errors by adding several functions as follows:
var test:World = new World(this, this);
function createWorld() {}
function getStepSize(temp) {}
function setStepSize(temp, temp2) {}
trace(test); // Output: [object World]
Both Flash CS4 porfessional and Flash Professional CS5.5 don’t have such class, “World”. I suspect Adobe left the unnecessary class in CS5 by mistake. You have to be careful if you define the class named “World” in CS5.
[postscript: 2011/09/23]
According to the comments below and the blog article “Flash CS5 Built-in Physics Discovered“, the class World is a part of physics engine in the inverse Inverse Kinematics framework. And once the API was planned to release with the “Physics” panel but was abandoned by Adobe.
Based on the blog the following code was written to test the library:
const COUNT:uint = 50;
var instances:Vector.<Shape> = drawShapes(COUNT);
var physics:PhysicsManager = new PhysicsManager(stage);
var myWorld:World = physics.createWorld();
assignPhysics();
myWorld.enableCollisions(true);
myWorld.setGravity(new Point(0, 200));
stage.addEventListener(MouseEvent.CLICK, startPhysics);
function startPhysics(eventObject:MouseEvent):void {
addEventListener(Event.ENTER_FRAME, animatePhysics);
}
function assignPhysics():void {
var myPoint:Point = new Point(1, 1);
for (var i:uint = 0; i < COUNT; i++) {
var instance:DisplayObject = instances[i];
var physicsObject:PhysObj = myWorld.addPhysObj(instance, myPoint, 0, false);
if (i % 2) {
physicsObject.setNonMoving(true);
}
}
}
function animatePhysics(eventObject:Event):void {
myWorld.updateAllObjects();
myWorld.step();
}
function drawShapes(count:uint):Vector.<Shape> {
var nStageWidth:int = stage.stageWidth;
var nStageHeight:int = stage.stageHeight;
var nWidth:Number = 25;
var nHeight:Number = 5;
var instances:Vector.<Shape> = new Vector.<Shape>(count);
for (var i:uint = 0; i < count; i++) {
var myShape:Shape = new Shape();
var myGraphics:Graphics = myShape.graphics;
myGraphics.beginFill(uint(0xFFFFFF * Math.random()));
myGraphics.drawRect(-nWidth / 2, -nHeight / 2, nWidth, nHeight);
myGraphics.endFill();
addChild(myShape);
instances[i] = myShape;
myShape.x = nStageWidth * Math.random();
myShape.y = nStageHeight * Math.random();
myShape.rotation = 360 * Math.random();
}
return instances;
}
Just copy the whole code and paste it into the first frame of the main timeline in Flash Professional CS5. Then do [Test Movie] and click on the stage. A half of instances randomly placed will fall down.

Instances are randomly placed on the stage

Click on the stage and a half of Instances fall down

Flash Professional CS5 includes the PffLib.swc library file in the application holder
The API of the physics engine is stored in the application folder of Flash CS5, Adobe Flash CS5/Common/Configuration/ActionScript 3.0/libs. You may use the file in CS5.5 as well by adding its folder path to the [Library path] in the [Advanced ActionScript 3.0 Settings].
14 Comments
That class is a part of physics engine (PffLib.swc in \Adobe Flash CS5\Common\Configuration\ActionScript 3.0\libs):
http://heftybyte.com/flash/flash-cs5-physics/
Can you be more specific. I have CS5.5, targeting Flash Player 9 and the code:
var test:World = new World();
throws two errors:
Scene 1, Layer ‘Layer 1′, Frame 1, Line 1 1046: Type was not found or was not a compile-time constant: World.
Scene 1, Layer ‘Layer 1′, Frame 1, Line 1 1180: Call to a possibly undefined method World.
this World Class is part of an undocumented builtin physics engine :
http://t.co/PQISQPZ
Could you decribeType it and post the results?
Oh I also experienced this !^!*@&!@ problem!! It really made me crazy. In fact, It’s a part of Flash CS5 Professional’s IK framework, but it is top-level class, so if you declare your own class World { … } and instantiate it, then you see that error. also, by the same reason, you can’t use PhysObj, Joint, Spring as a class name.
…Flash CS5\Common\Configuration\ActionScript 3.0\libs\ik.swc
Open this file as a zip and you can see catalog.xml. names in this file can’t be used as class names. oh I just saw another class, PhysSprite.
Flash CS includes a basic physic engine (PffLib.swc) with a few unfortunately named global classes: World, Joint, Spring, etc.
if you remeber the built in physics adobe advertised on 2009 MAX event, that’s exactly what that World is.
http://heftybyte.com/flash/flash-cs5-physics/
Have you tried using describeType to find out more about the class? I went from CS4 -> CS5.5 so I can’t test it myself.
That’s part of the Flash CS5’s built-in physics engine.
You should take a look at this, very interesting: http://heftybyte.com/flash/flash-cs5-physics/
(From the link above) the way to initialize “world” is:
var world:World = physicsManager.createWorld();
I think Adobe focused so much telling about the Packager for iPhone feature in CS5 that maybe they forgot telling us about this
That’s weird.
I actually just used a class named World in a recent project, but fortunately I was using Flash Develop instead of CS5.
Not a mistake – but evidence of the upcoming built-in physics engine! Read here: http://heftybyte.com/flash/flash-cs5-physics/
Thank you for all of your invaluable comments and information. I added the postscript into the article.
[...] import line, the error message is the same. Where is this World class coming from? I’ll let Fumio Nonaka from JActionScripters answer: According to […] the blog article “Flash CS5 Built-in Physics [...]