how to handle _root with mutliple swf

I was working to create a  flash-based football game application.  Inside the game, a football player moves in various direction when I press the arrow keys. However, it was not working fine after I dd some changes.

The code of football player goes like this.

function step(who) {
	//check to see if the football player in question is controlled by the player or by the computer
	if (_root["football"+who].code == "player") {
	....

It looked like a decent piece of code until I added some other features. The problem is I was loading some other .swf after loading this .swf. As a result, _root gets changed everytime a new movie is loaded. _root always point to latest .swf unless _lockroot is true.

this._lockroot = true;

Using the below code, I was able to ensure that the given .swf will be treated as root.

  onClipEvent (load)
  {
    this._lockroot = true;
  }
  game_mc.loadMovie ("football.swf");
Advertisements

how to create an application in Flex?

Create a user interface using MXML to accept user-supplied keywords and display photos

  • Write a method and event handler using ActionScript
  • Request and handle RSS data from Flickr using Flex HTTPService
  • Create a bindable XML variable used to populate a Tile component
  • Cast data as XML
  • Create a namespace for the XML thumbnail and description data
  • Create an item renderer to display photo thumbnail and description in the Tile component
  • Create a custom component
  • Customize the application display

tutorial link: http://learn.adobe.com/wiki/display/Flex/1d.+RIA+Tutorial