Skip to content

Toga Games

                               Game on!

Check it out. Pretty cool. I’m adding more to it as I have time.

Flash 3D Game Engine Evolution

To view the right click code in action click >> [Example]

Here is how to use right click in your Flash (AS3)

Inside your html page:

NOW, inside your Flash AS3 file:


// PUT INSIDE OF PACKAGE this top part
package {
import flash.display.*;
import flash.events.MouseEvent;
import flash.external.ExternalInterface;

// now inside a function inside your class....
public function Game () {
// this detects from outside flash so we can use right click
ExternalInterface.addCallback ("rightClick",RC);
}
function RC () {// add right click functionality here
ExternalInterface.call ("jalert", "");// this is telling that right is clicked in JS
_trace ("You right clicked!");
}

The javascript files are here: RIGHT CLICK CODES (javascript)

I am building a tower defense engine presently with my newly gained knowledge of AS3. I also have some plans on making some games that incorporate special right click code that allows the game to use the right mouse inputs.. yay! Battlemonger Tower Defense is in development.

To view the right click code in action click >> [Example]

This was another problem I had when learning AS3. The AS2 method was quite simple, but I had to search around for the proper AS3 method. So here it is.

Ok, this is inside my World.as class

You have to set the dynamically created movieclips into an array after you create them and then place them into the array with their iterated number (placing it into the array after creation “tiles[tileNumber]=t; tileNumber++)
so then we can access the tiles with: tiles[3].x, etc.. not bad at all.
============================================


public var tiles:Array=new Array;
private function build (vert:int,hort:int):void {
var map:Map = new Map();
trace("MAP: "+map.world1);
var startX=0;
var startY=0;
var step=40;
var stagger=0;
var a=0;
var b=0;
var tileNumber=0;
for (a=0; a < vert; a++) {
for (b=0; b < hort; b++) {
var t=new Tile;
t.x=step * stagger;
t.y=step * a;
t.num=tileNumber;
// this to be set by tile array
//t._spot=fn.randRange(0,tileSpots.length) - 1;
t._spot=map.world1[tileNumber];
trace (map.world1[tileNumber]);
t.gotoAndStop (t._spot+1);
t.addEventListener (MouseEvent.CLICK,tileChange);
t.addEventListener (MouseEvent.ROLL_OVER,updateToolTip);
_screen.addChild (t);
t.name="tile" + tileNumber;
var glow:TileGlow=new TileGlow;
glow.visible=false;
t.glow=glow;
t.addChild (glow);
tiles[tileNumber]=t;
stagger++;
tileNumber++;
}
stagger=0;
}
currentTile=t;
}

I am learning more AS3 as I work on current projects. I reluctantly came from AS2. I HAD to make this tutorial because I just figured this out and it’s frustrating when you don’t know how.

Just a quick how-to on accessing variables and arrays from another class file.

TestData.as – here is the data we wish to access that is in a separate class file for cleanliness purposes. Otherwise your class main class files get gigantic having all that extra data inside it.

package {

public class TestData {

public var tar:Array = new Array();
public function TestData ():void {
trace ("test data initialized but not yet loaded...");
tar.push ("kittens");
tar.push ("hamsters");
tar.push ("gerbils");
tar.push ("bunnies");
}

// #END END END END END END
}
}

Main.as (or whatever) – The data caller
[* note: you will find a bunch of extra stuff in here since this is mostly what I use in my main classes. Just pay attention to "public function test"]


package {
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.events.Event;
import flash.utils.Timer;

import org.application.*;
import org.console.*;

/* ======================================================= */
/****** ** UTILITY TEST ENGINE ** *******/
/*** Year: 2010 ***/
/** Ken Clinton **/
/** **/
/*** ADMIN@TOGAGAMES.COM **/
/** **/
/* ================================================ */

public class Utility extends Sprite {

public var fps:FPS;
public var settings:Settings;
public var stopLoss:StopLoss;

public function Utility ():void {
// LOAD GAME SETTINGS
settings = new Settings();

// WAIT TIL PRELOADER IS DONE
this.addEventListener (Event.ADDED_TO_STAGE,wait);
}
/*
WAITING FOR SECURITY CHECK
*/
public function wait (event:Event):void {
Global.data._game = this;
CustomMenu.buildMenu (this);
StopLoss.fraudCheck (this);
}
public function init ():void {
var timer:Timer=new Timer(Global.data._updatetime,0);// save game every x seconds
timer.addEventListener (TimerEvent.TIMER,timedLoop);
timer.start ();
this.addEventListener (Event.ENTER_FRAME,onRenderTick);
// host is good, so continue
fps = new FPS(695,35);
addChild (fps);
/*
RUN A TEST
*/
test ();
}
/*

PERFORM ALL YOUR TESTS HERE
*/
public function test ():void {
var td:TestData = new TestData;
var stuff = td.tar[0];
trace ("Array data: "+stuff); // traces "kittens"
}
/*

OUR LOOP RENDER / UPDATER, ENTER FRAME
*/
private function onRenderTick (event):void {
fps.addFrame ();
}
/*
UPDATE EVERY X SECONDS (GAME SAVES, ETC)
*/
private function timedLoop (e:TimerEvent):void {
//settings.update ();
}
// #END
}
}

Create a multiplayer userbase with playerio.

Free for 20gb, then 99 dollars per month.

PlayerRIO