A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: change variable value dynamically

Threaded View

  1. #1
    Member
    Join Date
    Sep 2010
    Posts
    32

    change variable value dynamically

    var game:Object = new Object;
    game.Tile0.frame = 1;
    game.Tile1.frame = 2;

    animation.gotoAndStop(game.Tile+i+.frame);

    need a way to change from tile0 to tile1 through variable




    Real Example::
    Code:
    var myMap:Array = [
    [1, 1, 1, 1, 1, 1, 1, 1], 
    [1, 0, 0, 0, 0, 0, 0, 1], 
    [1, 0, 1, 0, 0, 0, 0, 1], 
    [1, 0, 0, 0, 0, 1, 0, 1], 
    [1, 0, 0, 0, 0, 0, 0, 1], 
    [1, 1, 1, 1, 1, 1, 1, 1]
    ];
    
    
    var game:Object = new Object;
    game = {tileW:30, tileH:30};
    
    game.Tile0 = function () { };
    game.Tile0.walkable = true;
    game.Tile0.frame = 1;
    
    game.Tile1 = function () { };
    game.Tile1.walkable = false;
    game.Tile1.frame = 2;
    
    function buildMap(map) {
    
    	var mainMC:empty = new empty();
    	
    	
    	stage.addChild(mainMC);
    	
    	var mapWidth = map[0].length;
    	var mapHeight = map.length;
    	
    	for (var i = 0; i<mapHeight; ++i) {
    		for (var j = 0; j<mapWidth; ++j) {
    			
    			var D_tile:tile = new tile();
    			D_tile.x = (j*game.tileW);
    			D_tile.y = (i*game.tileH);
    			
    			
    			
    			
    			
    	
    			D_tile.gotoAndStop(game.Tile+map[i][j]+.frame);
    			
    			mainMC.addChild(D_tile);
    			
    
    			
    			
    			
    			
    		}
    	}
    	
    	
    	
    	
    	
    	
    	
    	
    
    }
    
    buildMap(myMap);
    Last edited by onenonly; 04-13-2011 at 11:22 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center