actionscript for flash game

I would like to add the flash game into the main flash movie

Page 1 of 1

0 Replies - 1833 Views - Last Post: 09 December 2008 - 01:19 PM

#1 Netty   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-December 08

actionscript for flash game

Posted 09 December 2008 - 01:19 PM

I want to include a football game (flash game) into my interactive letter project but it doesn't work. The game itself works so well but when i put it in the big project (interactive letter) the ball doesn't come up. could you mind me with this.

There're a lot of actionscript here

1) main action for the game
#include "mc_tween2.as"
import flash.geom.Point;
import flash.display.BitmapData;
Stage.showMenu = false;
Mouse.hide();

//Random number between two numbers
function randRange(min:Number, max:Number):Number {
	var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
	return randomNum;
}

//Hittest advanced.
MovieClip.prototype.pixelHitTest = function(mc:MovieClip):Boolean  {
	var thisBitmap:BitmapData = new BitmapData(this._width, this._height, true, 0);
	thisBitmap.draw(this);

	var mcBitmap:BitmapData = new BitmapData(mc._width, mc._height, true, 0);
	mcBitmap.draw(mc);

	if (thisBitmap.hitTest(new Point(this._x, this._y), 0xFF, mcBitmap, new Point(mc._x, mc._y))) {
		return true;
	}
	return false;
};

//Variables
this.gogogo= function() {
	cont = 0;
	level = 0;
	_root.life.gotoAndStop(1);
	gravity = 20;
	record.text = 0;
	points .text = 0;
	varpoints  = 0;
	varrecord = 0;
	wide  = high=75;
	lives = 1;
	_root.pointer._alpha = 1;
};

//Create
this.create = function() {
	if (lives<=3) {
		sound = new Sound(this);
		sound.attachSound("pitido");
		sound.start();
		//
		bola = attachMovie("bola", "bola"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:randRange(80, Stage.width-80), _y:-30});
		bola.mover();
		bola.dirx = Math.cos(angle*Math.PI/180)*firepower;
		bola.diry = 0;
		//
		level = 0;
		varpoints  = 0;
		points .text = varpoints;
		//
		_root.boot.tween("_xscale",100,.5,"easeOutQuad");
		_root.boot.tween("_yscale",100,.5,"easeOutQuad");
	} else {
		//Final
		cont = 0;
		_root.pointer._alpha = 100;
		//
		sound = new Sound(this);
		sound.attachSound("final");
		sound.start();
		//
		_root.boot.tween("_x",(Stage.width/2)-(_root.boot._width/2),.5,"easeOutExpo");
		_root.boot.tween("_xscale",100,.5,"easeOutExpo");
		_root.boot.tween("_yscale",100,.5,"easeOutExpo");
		_root.boot.tween("_rotation",0,.5,"easeOutExpo");
		_root.kickoff.tween("_x",225,1,"easeOutExpo");
	}
	cont = 0;
};

//Moves
MovieClip.prototype.mover = function() {
	this.onEnterFrame = function() {
		if (this.pixelHitTest(_root.boot)) {
			//By touching
			this._y -= gravity;//To avoid 2 touches to 1. 
			if (level>(-990)) {
				level -= 10;
				cont += 1;
				
			}
			//   
			sound = new Sound(this);
			sound.attachSound("pared");
			sound.start();
			//
			this.dirx = Math.cos(angle*Math.PI/180)*firepower;
			this.diry = randRange(-Stage.height-100, level);
			//scale
			scale1 = randRange(20, 100);
			scale2 = randRange(40, 100);
			this.tween("_xscale",scale1,.2,"easeOutQuad");
			this.tween("_yscale",scale1,.2,"easeOutQuad");
			_root.boot.tween("_xscale",scale2,.2,"easeOutQuad");
			_root.boot.tween("_yscale",scale2,.2,"easeOutQuad");
			wide  = high=75*scale2/100;
			//points 
			varpoints  += 1;
			points .text = varpoints;
		}
		//Rotation			 
		if (antx<this._x) {
			this._rotation += 5;
		} else {
			this._rotation -= 5;
		}
		antx = this._x;
		this._rotation += 2;

		//Movement
		num1 = randRange(0, Stage.width);
		num2 = randRange(100, Stage.height-100);
		mousex = _xmouse-(num1);
		mousey = (_ymouse-(num2))*-1;
		angle = Math.atan(mousey/mousex)/(Math.PI/180);
		angle = angle*-1;
		if (mousex<0) {
			angle += 180;
		}
		firepower = Math.sqrt(_root._xmouse*_root._xmouse+_root._ymouse*_root._ymouse);
		if (firepower>180) {
			firepower = 180;
		}
		//Limites			  
		if (this._x<=wide /2) {
			sound2 = new Sound(this);
			sound2.attachSound("toque");
			sound2.start();
			this._x = wide /2;
			this.dirx *= -1;
		}
		if (this._x>=Stage.width-wide /2) {
			sound2 = new Sound(this);
			sound2.attachSound("toque");
			sound2.start();
			this._x = Stage.width-wide /2;
			this.dirx *= -1;
		}
		//			  
		this.diry += gravity;
		this._x += this.dirx/20;
		this._y += this.diry/30;
		//If you fail
		if (this._y>Stage.height+high) {
			lives += 1;
			_root.life.gotoAndStop(lives);
			if (varpoints >varrecord) {
				varrecord = varpoints;
				record.text = varrecord;
				points .text = 0;
			}
			this.removeMovieClip();
			create();
		}
	};
};



2.code for the mouse (pointer movie clip)

onClipEvent (enterFrame) {
		this._x = _root._xmouse;
		this._y = _root._ymouse;
}



3. code for kickoff (movie clip)
onClipEvent (load) {
	_root.life.gotoAndStop(4);
	_root.lives=4;
}
on (release) {
	this.tween("_x",-235,.5,"easeOutExpo");
	_root.gogogo();
	_root.create();
}



4.
and code for the boot (movie clip)
onClipEvent (enterFrame) {
	if (_root.lives<=3) {
		delay = 0.6;
		xspeed = 0;
		xspeed = (_root._xmouse-this._x)*1.5+(xspeed*delay);
		if(xspeed>0){
			xspeed*=-1;
			}
		this.tween("_rotation",xspeed,.5,"easeOutExpo");
		this._x = _root._xmouse;

	}
}




That's all for the football game. I would like to know what code I should edit here in order to make it playable in the main movie (interactive letter). However, I'm not sure if the problem is in the football game or in the main movie. The main movie is a very long timeline animation with a little bit of actionscript.

Regards,
Netty

PS. The files are bigger than 1000k, so i couldn't attach them here.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1