bonjour,j'ai une lacune au niveau d'exécution de ce code sur adobe flash Professionnel CS6,il m'affiche un message d'erreur, voila le message:
Les polices doivent être incorporées pour tous les textes pouvant être modifiés à l'exécution, hormis pour les textes dont le paramètre "Utiliser les polices de périphérique" est activé. Utilisez la commande Texte > Incorporation de polices pour incorporer les polices.
TypeError: Error #1009: Il est impossible d'accéder à la propriété ou à la méthode d'une référence d'objet nul.
at jeusnake_fla::MainTimeline/initialize()
at jeusnake_fla::MainTimeline/frame1()
voici le code actionScript3:
import flash.display.MovieClip;
var container:Sprite;
var score:int = 0;
var headWidth:Number = 25; //width of snake head
var hudHeight:int = 50; //height of the hud placed at bottom of the stage
var columns:Number = stage.stageWidth/headWidth; //total num of columns for grid
var rows:Number = (stage.stageHeight - hudHeight)/headWidth; //total num of rows for grid
var food:Sprite; //holds snake’s food
var foodX:Number; //food’s x position
var foodY:Number; //food’s y position
var foodWidth:Number = headWidth; //same as snake’s head for a sake of game play
var direction:String; //set the direction of the snake
var running:Boolean = false;
var keyFrame:int;
var frameNum:int = 0; //current frame num
var span:int = 20;//num of frames between two keyframes
//Create grid of tiles
function grid()
{
for(var i:int = 0; i < rows; i++){
for(var j:int = 0; j < columns; j++) {
var tile:Sprite = new Tile(); //get tile from the library
//Arrange tiles to form a grid
tile.x = (headWidth/2) + (j * headWidth);
tile.y = (headWidth/2) + (i * headWidth);
addChild(tile);
}
}
}
grid();
var head:MovieClip; //holds snake’s head
var headX:Number; //head’s x position
var headY:Number; //head’s y position
var partsArr:Array = new Array(); //holds Snake’s head and body parts
var gameOver_DiagBox:MovieClip;
//Initialization
function initialize()
{
gameOver_DiagBox.visible = false;
//Since the head’s pivot is at the centre, adjust its position
var t1:Number = headX - headWidth/2;
var t2:Number = headY - headWidth/2;
head.x = t1;
head.y = t2;
//Get and place food from the library
food = new Food();
container.addChild(food);
//Random position of food
newFood();
}
initialize();
//Place the food at random position
function newFood()
{
foodX = Math.ceil(((stage.stageWidth-foodWidth)/(foodWidth))*Math.random())*foodWidth;
foodY = Math.ceil((((stage.stageHeight-hudHeight)-foodWidth)/(foodWidth))*Math.random())*foodWidth;