Hey Guys
Ive got a game at the moment, with 3 external classes (different .as files). Currently they ARE communiticating, but with the error:
TypeError: Error #1034: Type Coercion failed: cannot convert Frame1Bed$ to flash.display.DisplayObject.
at FrameFun/Frame1()
at FrameFun$iinit()
at Zelda_Main$iinit()
Any ideas?
Code:
Main:
package {
import flash.display.*;
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.Stage;
import flash.display.MovieClip;
import flash.text.*;
import flash.events.*;
import flash.ui.Mouse;
import Link;
import FrameFun;
//import CustomEvent;
//import PackageIncludes;
//import Mobs;
//import Lives;
//import Shop;
public class Zelda_Main extends MovieClip {
//variables
private var frameFun:FrameFun = new FrameFun();
public function zelda() {
//add children
//add GUI (for hp, exp, w/e)
//action event listener
}
public function Zelda_Main() {
trace("...game started...");
startGameButton.addEventListener(MouseEvent.CLICK, playGame);
//addEventListener(FrameFun());
}
public function playGame(event:MouseEvent):void {
gotoAndStop(1, "Scene 2");
var link:Link = new Link(stage);
}
}
}
Character:
package {
//Imports
import flash.display.*;
import flash.display.Sprite;
import flash.events.*;
import fl.motion.Color;
import flash.geom.ColorTransform;
import flash.display.Stage;
import flash.system.*;
//Imports from other dude
import flash.display.MovieClip;
import flash.display.Stage;
import flash.utils.Timer;
import flash.ui.Keyboard;
import flash.events.TimerEvent;
import flash.events.KeyboardEvent;
//SystemTotalMem:
//(In BYTES)
//My PC:
//Uni PC:
//CHANGE SPEED BACK TO 5 ONCE THIS **** IS WOKRING!
public class Link extends MovieClip {
//Variable for the frame number. This is useful for movement within the world.
public var frameNumber:Number;
//Saying the Arrow Keys.
private var leftArrow, rightArrow, upArrow, downArrow:Boolean;
//Setting up our Character.
public var link:mcLink;
//Speed
public var Speed:Number = 25;
//need to get stage reference from the root stage -> THANK YOU RYAN!
//see http://www.kirupa.com/forum/showthread.php?t=316865 for info --> THANK YOU RYAN!
//rememeber that this needs to be passed from root .as file --> THANK YOU RYAN!
private var swfStage = Stage;
public function Link(swfStage:Stage) {
trace("Link class running");
trace(System.totalMemory);
//LinkInit(null);
this.swfStage = swfStage;
link = new mcLink();
link.x = 450;
link.y = 350;
swfStage.addChild(link);
swfStage.addEventListener(Event.ENTER_FRAME, MoveLink);
swfStage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedDown);
swfStage.addEventListener(KeyboardEvent.KEY_UP, keyPressedUp);
}
public function LinkInit(event:TimerEvent) {
link = new mcLink();
link.x = 450;
link.y = 350;
addChild(link);
}
public function keyPressedDown(event:KeyboardEvent) {
//find out what key the user is pressing and set that boolean to true
//Taken from MinorTheftAuto
switch (event.keyCode) {
case 37 :
//left
leftArrow = true;
break;
case 39 :
//right
rightArrow = true;
break;
case 38 :
//up
upArrow = true;
break;
case 40 :
//down
downArrow = true;
break;
}
}//end function keyPressedDown //Key Pressed Down
public function keyPressedUp(event:KeyboardEvent) {
//find out what key the user has just released and set the boolean to false
//Taken from MinorTheftAuto
switch (event.keyCode) {
case 37 :
//left
leftArrow = false;
break;
case 39 :
//right
rightArrow = false;
break;
case 38 :
//up
upArrow = false;
break;
case 40 :
//down
downArrow = false;
break;
}
}//end function keyPressedUp //Key Pressed Up
public function MoveLink(event:Event):void {
if (leftArrow) {
//if the user presses the left arrow, rotate to the left/anticlockwise
moveLeft();
}
if (rightArrow) {
//if the user presses the right arrow, rotate to the right/clockwise
moveRight();
}
if (upArrow) {
//call the moveForward() function to move the Link forward
moveUp();
}
if (downArrow) {
moveDown();
}
}
public function moveLeft() {
link.x -= Speed;
//if link is facing right, flip image, then move left
}
public function moveRight() {
link.x += Speed;
//if link is facing left, flip image, then move right
}
public function moveUp() {
link.y -= Speed;
//use left or right facing direction
}
public function moveDown() {
link.y += Speed;
//use left or right facing direction
}
}
}
FrameFun:
This is about 5000 lines long, so Ill cut it down…
package {
import flash.display.*;
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.*;
import flash.geom.ColorTransform;
import flash.text.*;
import flash.ui.Mouse;
import fl.motion.Color;
import Link;
//import CustomEvent;
public class FrameFun extends EventDispatcher {
private var myLink = new mcLink();
public var Speed:Number = 25;
public function FrameFun():void {
trace("Banana walks into a bar");
if(myLink.currentFrame == 1) {
trace("You are on Frame One, BLAH");
Frame1();
if(myLink.x >= 750) {
myLink.gotoAndStop(2, "Scene 2");
}
}
}
public function Frame1():void {
myLink.currentFrame == 1;
trace("You are on Frame One (From Frame1())");
//Screen Wrapping
if(myLink.x == 750){
myLink.gotoAndStop(2)
}
//Collision Detection
if(myLink.hitTestObject(Frame1Bed)){
Speed -= Speed;
}
//Check how to hit the sides of the house!! (many MC's? (yeah... )) (no)
//BITMAP COLLISION THING!
//object = Frame1House
}
*upto frame 137*
}
Any ideas?
Thanks alot in advance everyone