Massively looks at the best free to play games

ActionScript: Learning from Neave's FlashEarth

flash earthSo I downloaded Neave's FlashEarth application that we love so much, but not only so I could see how he accessed the maps, but so I could see the easy code too. I was looking to spread some elements around a future project like he spreads the navigation and options in FlashEarth. First the code (edited for ease of use) then the explanation.

//initialize variables
var sw:Number = 0; // Stage width
var sh:Number = 0; // Stage height


// Position menu items at corners of the stage
this.onResize = function():Void {
sw = Stage.width || startWidth;
sh = Stage.height || startHeight;

//move left side to left of stage
topLeft_mc._x = bottomLeft_mc._x = Math.ceil((SIZE - sw) / 2);

//move right side to right of stage
topRight_mc._x = bottomRight_mc._x = Math.ceil((SIZE + sw) / 2);

//move top side to top of stage
topLeft_mc._y = topRight_mc._y = Math.ceil((SIZE - sh) / 2);

//move bottom side to bottom of stage
bottomLeft_mc._y = bottomRight_mc._y = Math.ceil((SIZE + sh) / 2);
};

//call resize elements once to initialize
this.onResize();

//tie resize elements to stage so when stage size
//is adjusted elements move around
Stage.addListener(this);

At first I saw the project and thought wow that must be hard, but then I saw the code and slapped my forehead (about the spreading at least). Simply put, when the Flash project is streched it automatically re-positions the four elements in the corners of the stage. This way your project is size dependent and not zoom dependent. Oh and one more very important thing:

Stage.scaleMode = "noScale";

This needs to be placed at the start of your movie to keep the zoom effect in check.

 
News
Macromedia (141)
Innovation (164)
Merger (41)
Releases (65)
WIN Business (24)
Events
MAX (26)
FlashForward (8)
MMUGs (16)
Webinars (4)
Learning
ActionScript (49)
Designer Certification (5)
Developer Certification (6)
Ideas (163)
Links (83)
Samples (57)
Tips and Tricks (98)
Tutorials (45)
Design & Development
Accessibility (14)
Ad Design (27)
Art (94)
Components (6)
Extensions (17)
Games (65)
Rich Internet Applications (99)
Sound (38)
Video (65)
Web Standards (33)
Software
Flash 8 (103)
Flash MX2004 (92)
Flash Paper 2 (3)
Flash Player 8 (55)
Flash MX2004 Professional (44)
Flash Lite (24)
Flash Platform (91)
Flash Remoting (3)
Flash Communications Server MX (8)
Flash Video (24)
Flash Paper (3)
Macromedia Contribute (2)
Macromedia Flex (8)
8Ball (15)
Maelstrom (19)
Software Updates (34)
Beta (22)
Bugs (14)
Studio 8 (25)

RESOURCES

RSS NEWSFEEDS

Powered by Blogsmith

Other Weblogs Inc. Network blogs you might be interested in: