Why am i getting a syntax error in flash? - actionscript-3

Below is my actionscript code for flash, but im getting an syntax error on line 65, any ideas why? The code is for a game called escape the room, where the player must find objects to move on and open the door. When i run the flash movie it keeps flashing and i cant drag anything, which im meant to be able too because thats what the code is about.
stop();
inventorykey_mc.alpha = 0;
inventorypotion_mc.alpha = 0;
inventoryswipecard_mc.alpha = 0;
key_mc.addEventListener(MouseEvent.MOUSE_DOWN, objectFound);
potion_mc.addEventListener(MouseEvent.MOUSE_DOWN, objectFound);
swipecard_mc.addEventListener(MouseEvent.MOUSE_DOWN, objectFound);
var founditems:Number=0;
function pickupObject(event:MouseEvent):void {
event.target.startDrag(true);
}
function dropObject(event:MouseEvent):void {
event.target.stopDrag();
}
crate1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
crate1_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
crate1_mc.buttonMode=true;
crate2_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
crate2_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
crate2_mc.buttonMode=true;
crate3_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
crate3_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
crate3_mc.buttonMode=true;
crate4_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
crate4_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
crate4_mc.buttonMode=true;
drum1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
drum1_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
drum1_mc.buttonMode=true;
drum2_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
drum2_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
drum2_mc.buttonMode=true;
drum3_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
drum3_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
drum3_mc.buttonMode=true;
bin1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
bin1_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
bin1_mc.buttonMode=true;
function escapeRoom(event:MouseEvent):void {
gotoAndStop(2);
}
function objectFound(event:MouseEvent):void {
var inventoryName:String = "inventory" + event.target.name;
var inventoryItem:DisplayObject = getChildByName(inventoryName);
event.target.alpha = inventoryItem.alpha = 100;
founditems ++;
event.target.alpha = 0;
*if(founditems = = 3){*
door_btn.addEventListener(MouseEvent.MOUSE_DOWN, escapeRoom);
}
}

Related

Drag and drop game sort items to three targets

Please I need some help. I have spent 2 weeks trying to make a drag and drop game In cs4 actionscript 3.0 and am about to give up. I have gotten help so far, but the best suggestion I got was try and start from scratch instead of decompiling someone else's work. so here it is
I have an array that looks like this
var answername:Array = new Array();
var answerdest:Array = new Array();
answername[0] = "gravel";
answerdest[0] = "1";
answername[1] = "Nuts and boltsl";
answerdest[1] = "1";
answername[2] = "water";
answerdest[2] = "2";
answername[3] = "gold";
answerdest[3] = "3";
answername[4] = "Iron";
answerdest[4] = "3";
I need three targets,
and the ability to place the name of the item in my array (this is just a short piece of it) on the screen, if it is dropped on the target matching the answerdest number tor that item it is placed in a column, and the next item my array appears. If not it returns to its starting position. This seems like it should be easy to do but I am not a computer teacher I am a science teacher that is trying to make something for my student to use. I have basic coding skills for cs4.
This is as far as i have gotten but can not Figure out how to get the drag and drop part to check if it is in the correct spot. And get to to create a new drag-able if the answer is correct.
I have created an answer target named "Answer1",
var objectoriginalX:Number;
var objectoriginalY:Number;
Atom.buttonMode = true;
Atom.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
Atom.addEventListener(MouseEvent.MOUSE_UP, dropObject);
Matter.buttonMode = true;
Matter.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
Matter.addEventListener(MouseEvent.MOUSE_UP, dropObject);
function pickupObject(event:MouseEvent):void {
event.target.startDrag();
event.target.parent.addChild(event.target);
}
var dropCount:int = 0;
var dbCount:int=0;
var dbutton0;
function dropObject (event:MouseEvent):void
{
{
event.target.stopDrag();
var targetName = Answer1;
trace (targetName);
var matchingTarget:DisplayObject = getChildByName(targetName);
if (event.target.dropTarget != null && event.target.dropTarget.parent == answerdest[1])
{
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
event.target.removeEventListener(MouseEvent.MOUSE_UP, dropObject);
event.target.buttonMode = false;
alpha = .8
dropCount ++;
event.target.x = 10
event.target.y = (Number(dropCount) * 100);
trace ("hit");
trace (dropCount);
} else
{
event.target.x = 100;
event.target.y = 111;
trace ("miss");
}
}
}
var answername:Array = new Array();
var answerdest:Array = new Array();
answername[0] = "gravel";
answerdest[0] = "1";
answername[1] = "Nuts and boltsl";
answerdest[1] = "Answer1";
answername[2] = "water";
answerdest[2] = "2";
answername[3] = "gold";
answerdest[3] = "3";
answername[4] = "Iron";
answerdest[4] = "3";
text3
text3.text = answername[1];
var myText:TextField = new TextField();
Atom.addChild(myText);
myText.text = answername[1] ;
Thanks for your help. I do not know if I am even on the correct track to do what I need it to do.
partial answer
var answername:Array = new Array();
var answerdest:Array = new Array();
answername[0] = "gravel";
answerdest[0] = "1";
answername[1] = "Nuts and boltsl";
answerdest[1] = "Answer1";
answername[2] = "water";
answerdest[2] = "2";
answername[3] = "gold";
answerdest[3] = "3";
answername[4] = "Iron";
answerdest[4] = "3";
text3
text3.text = answername[1];
This is pretty messy. I'm going to show a slightly better way. Even my method here isn't the best, but it's similar enough to what you are doing to not be hard to adopt.
var answer:Array = [
{_name:"gravel",dest:"1"},
{_name:"Nuts and bolts",dest:"Answer1"},
{_name:"water",dest:"2"},
{_name:"gold",dest:"3"},
{_name:"Iron",dest:"4"}
];
text3 // what is this supposed to do? I didn't get rid of it. But just a string sitting in the middle of your code should be throwing an error. I'd get rid of it.
//text3.text = answername[1]; // now we have a better way!
text3.text = answer[1]._name;
I know this doesn't directly help solve your problem but let's clean up your code and eventually we will figure it out. I just couldn't explain this in just a comment.
var objectoriginalX:Number;
var objectoriginalY:Number;
Atom.buttonMode = true;
Atom.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
Atom.addEventListener(MouseEvent.MOUSE_UP, dropObject);
Matter.buttonMode = true;
Matter.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
Matter.addEventListener(MouseEvent.MOUSE_UP, dropObject);
function pickupObject(event:MouseEvent):void {
event.target.startDrag();
event.target.parent.addChild(event.target);
}
var dropCount:int = 0;
var dbCount:int=0;
var dbutton0;
function dropObject (event:MouseEvent):void
{
event.target.stopDrag();
var targetName = Answer1;
trace (targetName);
var matchingTarget:DisplayObject = getChildByName(targetName);
if (event.target.dropTarget != null && event.target.dropTarget.parent == answer[1].dest) // red flag here!
//dest is a String and .parent is a MovieClip.
//They can never be equal. This block of code would never run like this.
{
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
event.target.removeEventListener(MouseEvent.MOUSE_UP, dropObject);
event.target.buttonMode = false;
alpha = .8
dropCount ++;
event.target.x = 10
event.target.y = (Number(dropCount) * 100);
trace ("hit");
trace (dropCount);
} else
{
event.target.x = 100;
event.target.y = 111;
trace ("miss");
}
}
var answer:Array = [
{_name:"gravel",dest:"1"},
{_name:"Nuts and bolts",dest:"Answer1"},
{_name:"water",dest:"2"},
{_name:"gold",dest:"3"},
{_name:"Iron",dest:"4"}
];
text3.text = answer[1]._name;
var myText:TextField = new TextField();
Atom.addChild(myText);
myText.text = answer[1]._name;

How do I stop my cursor from sticking to objects in flash?

So I've created a game where you must find 3 items, before clicking on the door and winning the game, so theres a few things that stuffing up my game. When you open the game and run it you will see 2 grey rocks on the left hand side, when i click to drag them they stick to the cursor, but when i click the crates to drag them they don't stick, how can i make it like the crates?
stop();
inventorycrowbar_mc.alpha = 0;
inventorypotion_mc.alpha = 0;
inventoryflashlight_mc.alpha = 0;
crowbar_mc.addEventListener(MouseEvent.MOUSE_DOWN, objectFound);
potion_mc.addEventListener(MouseEvent.MOUSE_DOWN, objectFound);
flashlight_mc.addEventListener(MouseEvent.MOUSE_DOWN, objectFound);
var founditems:Number=0;
function pickupObject(event:MouseEvent):void {
event.target.startDrag(true);
}
function dropObject(event:MouseEvent):void {
event.target.stopDrag();
}
crate1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
crate1_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
crate1_mc.buttonMode=true;
crate2_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
crate2_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
crate2_mc.buttonMode=true;
crate3_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
crate3_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
crate3_mc.buttonMode=true;
crate4_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
crate4_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
crate4_mc.buttonMode=true;
boulder1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
boulder1_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
boulder1_mc.buttonMode=true;
boulder2_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
boulder2_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
boulder2_mc.buttonMode=true;
drum3_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
drum3_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
drum3_mc.buttonMode=true;
grass_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
grass_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
grass_mc.buttonMode=true;
function escapeRoom(event:MouseEvent):void {
gotoAndStop(2);
}
function objectFound(event:MouseEvent):void {
var inventoryName:String = "inventory" + event.target.name;
var inventoryItem:DisplayObject = getChildByName(inventoryName);
event.target.alpha = inventoryItem.alpha = 100;
founditems ++;
event.target.alpha = 0;
if(founditems == 3){
door_btn.addEventListener(MouseEvent.MOUSE_DOWN, escapeRoom);
}
}
I've attached my flash projection the link below.
https://drive.google.com/file/d/0B-EnwwKnY8EqbDNSX0JyV01NeTA/view?usp=sharing
The game isn't finished so theres a few messed up things as i needed to re-theme the game,just ignore them. The 3 items to find are flashlight, potion and a red wrench, then click on the door to win.

1151: A conflict exists with definition, i dont understnad

I am having an error 1151 with AS3
it says
1151: A conflict exists with definition founditems in namespace internal.
I don't understand what I have to change
here it the script I am having the error with
var founditems:Number = 0;
the full script is below
THANKS :D
stop();
inventoryknife.alpha = 0;
inventoryaxe.alpha = 0;
inventoryesports.alpha = 0;
esports.addEventListener(MouseEvent.MOUSE_DOWN, objectFound);
axe.addEventListener(MouseEvent.MOUSE_DOWN, objectFound);
knife.addEventListener(MouseEvent.MOUSE_DOWN, objectFound);
var founditems:Number = 0;
can1.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
can1.addEventListener(MouseEvent.MOUSE_UP, dropObject);
can1.buttonMode = true;
can2.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
can2.addEventListener(MouseEvent.MOUSE_UP, dropObject);
can2.buttonMode = true;
can3.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
can3.addEventListener(MouseEvent.MOUSE_UP, dropObject);
can3.buttonMode = true;
can4.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
can4.addEventListener(MouseEvent.MOUSE_UP, dropObject);
can4.buttonMode = true;
brick1.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
brick1.addEventListener(MouseEvent.MOUSE_UP, dropObject);
brick1.buttonMode = true;
brick2.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
brick2.addEventListener(MouseEvent.MOUSE_UP, dropObject);
brick2.buttonMode = true;
brick3.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
brick3.addEventListener(MouseEvent.MOUSE_UP, dropObject);
brick3.buttonMode = true;
brick4.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
brick4.addEventListener(MouseEvent.MOUSE_UP, dropObject);
brick4.buttonMode = true;
brick5.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
brick5.addEventListener(MouseEvent.MOUSE_UP, dropObject);
brick5.buttonMode = true;
brick6.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
brick6.addEventListener(MouseEvent.MOUSE_UP, dropObject);
brick6.buttonMode = true;
brick7.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
brick7.addEventListener(MouseEvent.MOUSE_UP, dropObject);
brick7.buttonMode = true;
brick8.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
brick8.addEventListener(MouseEvent.MOUSE_UP, dropObject);
brick8.buttonMode = true;
brick9.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
brick9.addEventListener(MouseEvent.MOUSE_UP, dropObject);
brick9.buttonMode = true;
brick10.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
brick10.addEventListener(MouseEvent.MOUSE_UP, dropObject);
brick10.buttonMode = true;
crate1.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
crate1.addEventListener(MouseEvent.MOUSE_UP, dropObject);
crate1.buttonMode = true;
crate2.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
crate2.addEventListener(MouseEvent.MOUSE_UP, dropObject);
crate2.buttonMode = true;
crate3.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
crate3.addEventListener(MouseEvent.MOUSE_UP, dropObject);
crate3.buttonMode = true;
crate4.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
crate4.addEventListener(MouseEvent.MOUSE_UP, dropObject);
crate4.buttonMode = true;
tile1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
tile1_mc.addEventListener(MouseEvent.MOUSE_UP, dropObject);
tile1_mc.buttonMode = true;
{
var inventoryName:String = "inventory" + event.target.name;
var inventoryItem:DisplayObject = getChildByName(inventoryName);
event.target.alpha = inventoryItem.alpha = 100;
founditems ++;
event.target.alpha = 0;
if(founditems == 3)
{
door2_btn.addEventListener(MouseEvent.MOUSE_DOWN, escapeRoom);
}
}
The error is in namespace internal. You write code on timeline (very bad practice) it maybe in another keyframe at the same frame # that variable is already defined. Or you may have some instance on stage with the same instance name...

HTML5, Easel.js game problems

Been working on an easel game tutorial that involves an animated character going across the screen and avoiding crates falling from above. I've followed the code in the tutorial exactly but no joy;nothing seems to be loading (including images which are mapped correctly). No errors regarding syntax seem to occur so not sure what the problem is. It's a fair bit of code so totally understand if no-one has the time but just in case here it is ;
Site Page code (ill post the individual JavaScript file codes if anyone is interested;
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<style>
body {
background-color: #000;
}
</style>
<script src="lib/easeljs-0.6.0.min.js"></script>
<script src="JS/Platform.js"></script>
<script src="JS/Hero.js"></script>
<script src="JS/Crate.js"></script>
<script>
var KEYCODE_SPACE = 32, KEYCODE_LEFT = 37, KEYCODE_RIGHT = 39;
var canvas, stage, lfheld, rtheld, platforms, crates, hero, heroCenter, key, door, gameTxt;
var keyDn = false, play=true, dir="right";
var loaded = 0, vy = 0, vx = 0;
var jumping = false, inAir = true, gravity = 2;
var img = new Image();
var bgimg = new Image();
var kimg = new Image();
var dimg = new Image();
var platformW = [300, 100, 180, 260, 260, 100, 100];
var platformX = [40, 220, 320, 580, 700, 760, 760];
var platformY = [460, 380, 300, 250, 550, 350, 450];
document.onkeydown=handleKeyDown;
document.onkeyup=handleKeyUp;
function init(){
canvas = document.getElementById("canvas");
stage = new createjs.Stage(canvas);
bgimg.onload = this.handleImageLoad;
bgimg.src = "img/scene.jpg";
kimg.onload = this.handleImageLoad;
kimg.src="img/key.png";
dimg.onload = this.handleImageLoad;
dimg.src = "img/door.jpg";
img.onload = this.handleImageLoad;
img.src = "img/hero.png";
}
function handleImageLoad(event) {
loaded+=1;
if (loaded==4){
start();
}
}
function handleKeyDown(e) {
if(!e){ var e = window.event; }
switch(e.keycode) {
case KEYCODE_LEFT: lfHeld = true;
dir="left"; break;
case KEYCODE_RIGHT: rtHeld = true;
dir="right"; break;
case KEYCODE_SPACE: jump(); break;
}
}
function handleKeyUp(e) {
if(!e){ var e = window.event; }
switch(e.keycode) {
case KEYCODE_LEFT: lfHeld = false;
keyDn=false; hero.gotoAndStop("idle_h"); break;
case KEYCODE_RIGHT: rtHeld = false;
keyDn=false; hero.gotoAndStop("idle"); break;
}
}
function start(){
var bg = new createjs.Bitmap(bgimg);
stage.addChild(bg);
door = new createjs.Bitmap(dimg);
door.x = 131;
door.y = 384;
stage.addChild(door);
hero = new Hero(img);
hero.x = 80;
hero.y = 450;
stage.addChild(Hero);
crates = new Array();
paltforms = new Array();
for(i=0; i < platformW.length; i++){
var platform = new Platform(platformW[i],20);
platforms.push(platform);
stage.addChild(platform);
platform.x = platformX[i];
platform.y = platformY[i];
}
for(j=0; j < 5; j++){
var crate = new Crate();
crates.push(crate);
stage.addChild(crate);
resetCrates(crate);
}
key = new createjs.Bitmap(kimg);
key.x = 900;
key.y = 490;
stage.addChild(key);
Ticker.setFPS(30);
Ticker.addListener(window);
stage.update();
}
function tick() {
heroCenter = hero.y-40;
if (play){
vy+=gravity;
if (inAir){
hero.y+=vy;
}
if (vy>15){
vy=15;
}
for(i=0; i < platforms.length; i++){
if (hero.y >= platforms[i].y && hero.y<=(platforms[i].y+platforms[i].height) && hero.x>
platforms[i].x && hero.x<(platforms[i].
x+platforms[i].width)){;
hero.y=platforms[i].y;
vy=0;
jumping = false;
inAir = false;
break;
}else{
inAir = true;
}
}
for(j=0; j < crates.length; j++){
var ct = crates[j];
ct.y+=ct.speed;
ct.rotation+=3;
if (ct.y>650){
resetCrates(ct);
}
if (collisionHero (ct.x, ct.y, 20)){
gameOver();}
}
if (collisionHero (key.x+20, key.y+20,
20)){
key.visible=false;
door.visible=false;
}
if (collisionHero (door.x+20, door.y+40,
20) && key.visible==false){nextLevel();}
if (lfHeld){vx = -5;}
if (rtHeld){vx = 5;}
if(lfHeld && keyDn==false && inAir==false)
{
hero.gotoAndPlay("walk_h");
keyDn=true;
}
if(rtHeld && keyDn==false &&
inAir==false){
hero.gotoAndPlay("walk");
keyDn=true;
}
if (dir=="left" && keyDn==false &&
inAir==false){
hero.gotoAndStop("idle_h");
}
if (dir=="right" && keyDn==false &&
inAir==false){
hero.gotoAndStop("idle");
}
hero.x+=vx;
vx=vx*0.5;
if (hero.y>610){
gameOver();
}
}
stage.update();
}
function end(){
play=false;
var l = crates.length;
for (var i=0; i<l; i++){
var c = crates[i];
resetCrates(c);
}
hero.visible=false;
stage.update();
}
function nextLevel(){
gameTxt = new createjs.Text("Well Done\n\n",
"36px Arial", "#000");
gameTxt.text += "Prepare for Level 2";
gameTxt.textAlign = "center";
gameTxt.x = canvas.width / 2;
gameTxt.y = canvas.height / 4;
stage.addChild(gameTxt);
end();
}
function gameOver(){
gameTxt = new createjs.Text("Game Over\n\n",
"36px Arial", "#000");
gameTxt.text += "Click to Play Again.";
gameTxt.textAlign = "center";
gameTxt.x = canvas.width / 2;
gameTxt.y = canvas.height / 4;
stage.addChild(gameTxt);
end();
canvas.onclick = handleClick;
}
function handleClick() {
canvas.onclick = null;
hero.visible=true;
hero.x = 80;
hero.y = 450;
door.visible=true;
key.visible=true;
stage.removeChild(gameTxt);
play=true;
}
function collisionHero (xPos, yPos,
Radius){
var distX = xPos - hero.x;
var distY = yPos - heroCenter;
var distR = Radius + 20;
if (distX * distX + distY * distY <=
distR * distR){
return true;
}
}
function jump(){
if (jumping == false && inAir == false){
if (dir=="right"){
hero.gotoAndStop("jump");
}else{
hero.gotoAndStop("jump_h");
}
hero.y -=20;
vy = -25;
jumping = true;
keyDn=false;
}
}
function resetCrates(crt) {
crt.x = canvas.width * Math.random()|0;
crt.y = 0 - Math.random()*500;
crt.speed = (Math.random()*5)+8;
}
</script>
<title>Game</title>
</head>
<body onload="init();">
<canvas id="canvas" width="960px" height="600px"></canvas>
</body>
</html>
Adding the js files as listed in the header.
Platform.js:
(function(window) {
function Platform(w,h) {
this.width = w;
this.height = h;
this.initialize();
}
Platform.prototype = new createjs.Container ();
Platform.prototype.platformBody = null;
Platform.prototype.Container_initialize = Platform.prototype.initialize;
Platform.prototype.initialize = function() {
this.Container_initialize();
this.platformBody = new createjs.Shape();
this.addChild(this.platformBody);
this.makeShape();
}
Platform.prototype.makeShape = function() {
var g = this.platformBody.graphics;
g.drawRect(0,0,this.width,this.height);
}
window.Platform = Platform;
}(window));
Hero.js
(function(window) {
function Hero(imgHero) {
this.initialize(imgHero);
}
Hero.prototype = new createjs.BitmapAnimation();
Hero.prototype.Animation_initialize = Hero.prototype.initialize;
Hero.prototype.initialize = function(imgHero) {
var spriteSheet = new createjs.SpriteSheet({
images: [imgHero],
frames: {width: 60, height: 85, regX: 29, regY: 80}, animations: {
walk: [0, 19, "walk"],
idle: [20, 20],
jump: [21, 21] } });
SpriteSheetUtils
.addFlippedFrames(spriteSheet, true, false,
false);
this.Animation_initialize(spriteSheet);
this.gotoAndStop("idle");
}
window.Hero = Hero;
}(window));
Crate.js
(function(window) {
function Crate() {
this.initialize();
}
Crate.prototype = new createjs.Container();
Crate.prototype.img = new Image();
Crate.prototype.Container_initialize =
Crate.prototype.initialize;
Crate.prototype.initialize = function() {
this.Container_initialize();
var bmp = new createjs.Bitmap("img/crate.jpg");
bmp.x=-20;
bmp.y=-20;
this.addChild(bmp);}
window.Crate = Crate;
}(window));
I noticed that you try to initialize the EaselJS-objects without a namespace:
stage = new Stage(canvas);
But since 0.5.0 you have to use the createjs-namespace(or map the namespace to window before you do anything)
So what you would have to do now will ALL easelJS-classes is to add a createjs. before them when you are creating a new instance like this:
stage = new createjs.Stage(canvas);
Not sure if that's everything, but it's a start, hope this helps.
You can read more on CreateJS namepsacing here: https://github.com/CreateJS/EaselJS/blob/master/README_CREATEJS_NAMESPACE.txt

as3 child as movieclip - won't accept functions

this follows on from my last question which I thought was answered but for some reason when I treat a child of my stage (display object) as a movieclip I can't then apply the usual functions that I want to:
var mc1:MovieClip = this.getChildByName("mc1") as MovieClip;
if(mc1) {
mc1.useHandCursor = true;
mc1.buttonMode = true;
mc1.addEventListener(MouseEvent.CLICK, fillDriveway);
}
Any wisdom would greatly appreciated... and sorry for asking such a similar question as previous...
Thanks in advance.
EDIT: More code from the AS on this project for context:
import flash.display.*
ImageUploader.visible = false;
function showUploader(e:MouseEvent):void {
ImageUploader.visible = true;
ImageUploader.gotoAndPlay(2);
}
pic.addEventListener(MouseEvent.CLICK,addNewPoint);
var n:Number = 0;
var joinPointsArray:Array = new Array;
function addNewPoint(e:MouseEvent):void {
n++;
pointNo.text = String(n);
if(n==1){
var nextPoint:MovieClip = new mcstart();
addChild(nextPoint);
nextPoint.name = "mc"+pointNo.text;
nextPoint.x = e.target.mouseX;
nextPoint.y = e.target.mouseY;
}else{
var nextPoint2:MovieClip = new newPoint();
addChild(nextPoint2);
nextPoint2.name = "mc"+pointNo.text;
nextPoint2.x = e.target.mouseX;
nextPoint2.y = e.target.mouseY;
}
var joinPoints:MovieClip = new MovieClip();
this.addChild(joinPoints);
joinPointsArray.push(joinPoints);
joinPoints.graphics.lineStyle(0.5,0xFF0000);
joinPoints.graphics.moveTo(this.getChildByName("mc1").x, this.getChildByName("mc1").y);
for(var i:int=2; i<=n; ++i){
joinPoints.graphics.lineTo(this.getChildByName("mc"+i).x, this.getChildByName("mc"+i).y);
}
}
pic.addEventListener(MouseEvent.CLICK, addNewPoint);
function fillDriveway(eventObject:MouseEvent) {
var joinPoints:MovieClip = new MovieClip();
this.addChild(joinPoints);
for(var p:int=0; p<(joinPointsArray.length); ++p) {
joinPointsArray[p].alpha = 0;
}
this.getChildByName("mc1").alpha = 0;
joinPoints.graphics.beginFill(0xFFFFFF, 0.7);
joinPoints.graphics.moveTo(this.getChildByName("mc1").x, this.getChildByName("mc1").y);
for(var m:int=2; m<=n; ++m){
joinPoints.graphics.lineTo(this.getChildByName("mc"+m).x, this.getChildByName("mc"+m).y);
}
joinPoints.name = "driveshape";
filledDrive.text = "filled";
}
function undoit(eventObject:MouseEvent) {
if(n > 0) {
if(filledDrive.text.indexOf("filled") != -1) {
this.removeChild(this.getChildAt(this.numChildren -1));
filledDrive.text = "";
}else{
this.removeChild(this.getChildAt(this.numChildren -1));
this.removeChild(this.getChildAt(this.numChildren -1));
n--;
pointNo.text = String(n);
}
}
}
function maskDrive(eventObject:MouseEvent) {
if(filledDrive.text.indexOf("filled") != -1) {
var finishA:MovieClip = new finishMC();
this.addChild(finishA);
finishA.x = 310;
finishA.y = 100;
finishA.mask = getChildByName("driveshape");
finishA.gotoAndPlay(2);
}
}
//BTN RollOvers
function btn1over(myEvent:MouseEvent) {
btn1.gotoAndPlay(2);
}
function btn1out(myEvent:MouseEvent) {
btn1.gotoAndPlay(11);
}
function btn2over(myEvent:MouseEvent) {
btn2.gotoAndPlay(2);
}
function btn2out(myEvent:MouseEvent) {
btn2.gotoAndPlay(11);
}
function btn3over(myEvent:MouseEvent) {
btn3.gotoAndPlay(2);
}
function btn3out(myEvent:MouseEvent) {
btn3.gotoAndPlay(11);
}
function undoover(myEvent:MouseEvent) {
undo.gotoAndPlay(2);
}
function undoout(myEvent:MouseEvent) {
undo.gotoAndPlay(11);
}
//BTN Calls
btn1HIT.addEventListener(MouseEvent.CLICK, fillDriveway);
btn1HIT.addEventListener(MouseEvent.ROLL_OVER, btn1over);
btn1HIT.addEventListener(MouseEvent.ROLL_OUT, btn1out);
btn1HIT.buttonMode = true;
btn1HIT.useHandCursor = true;
btn2HIT.addEventListener(MouseEvent.CLICK, maskDrive);
btn2HIT.addEventListener(MouseEvent.ROLL_OVER, btn2over);
btn2HIT.addEventListener(MouseEvent.ROLL_OUT, btn2out);
btn2HIT.buttonMode = true;
btn2HIT.useHandCursor = true;
btn3HIT.buttonMode = true;
btn3HIT.useHandCursor = true;
btn3HIT.addEventListener(MouseEvent.ROLL_OVER, btn3over);
btn3HIT.addEventListener(MouseEvent.ROLL_OUT, btn3out);
btn3HIT.addEventListener(MouseEvent.CLICK, showUploader);
undoHIT.addEventListener(MouseEvent.CLICK, undoit);
undoHIT.addEventListener(MouseEvent.ROLL_OVER, undoover);
undoHIT.addEventListener(MouseEvent.ROLL_OUT, undoout);
undoHIT.buttonMode = true;
undoHIT.useHandCursor = true;
var mc1:MovieClip = this.getChildByName("mc1") as MovieClip;
if(mc1) {
mc1.useHandCursor = true;
mc1.buttonMode = true;
mc1.addEventListener(MouseEvent.CLICK, fillDriveway);
}
Are you sure the movieclip is placed on stage or actually converted to movieclip?
Try stage.getChildByName(). Where did you place this code? Inside a frame or inside a main document class? To be sure you can check the childs are added on stage and see what their names are.
You can use this code
for ( var i :int = 0; i < this.numChildren; i++ )
{
babe = this.getChildAt( i );
if ( babe is MovieClip) {
trace( babe.name);
}
}
I've also seen this, not sure if it works.
if (stage.contains(mc1)) {
}
Wahoo! Figured it out!
By popping
var mc1:MovieClip = this.getChildByName("mc1") as MovieClip;
at the end of my AS I was referring to the child "mc1" before it existed - it isn't created until the user clicks somewhere on the "pic" movieclip. So the solution was to bung my actions for "mc1" (including declaring it as a MovieClip) into a separate function:
function createstartEndMC():void {
var startEnd:MovieClip = (this.getChildByName("mc1")) as MovieClip;
startEnd.useHandCursor = true;
startEnd.buttonMode = true;
startEnd.addEventListener(MouseEvent.CLICK, fillDriveway);
}
and then to call this function AFTER "mc1" child is created:
function addNewPoint(e:MouseEvent):void {
n++;
pointNo.text = String(n);
if(n==1){
var nextPoint:MovieClip = new mcstart();
addChild(nextPoint);
nextPoint.name = "mc"+pointNo.text;
nextPoint.x = e.target.mouseX;
nextPoint.y = e.target.mouseY;
createstartEndMC();
}
Finally it works and "mc1" (or "startEnd" as I call it once it's created and made into an MC) finally behaves as a normal timeline MC should!
I'm so happy - thanks for all your guidance!
Cam