AS3- ReferenceError: Error #1069: Property not found - actionscript-3

Can someone tell me why I get this error?
ReferenceError: Error #1069: Property roll_mc not found on com.usmanzubairi.theAges.TheAges and there is no default value.
at com.usmanzubairi.theAges::PirGame/rolling()
package com.usmanzubairi.theAges
{
import flash.display.MovieClip;
import flash.events.*;
import flash.media.*;
public class TheAges extends MovieClip
{
private var game:PirGame;
private var game2:PreGame;
private var game3:SupGame;
public function TheAges()
{
stage.addEventListener(MouseEvent.CLICK, startGame);
}
private function startGame(event:Event):void
{
if (event.target != player_btn)
{
removeEventListener(MouseEvent.CLICK, startGame);
game = new PirGame();
addChild(game);
}
else
{
addChild(player_mc);
player_mc.visible = true;
player_mc.play();
}
if (event.target == player_mc.tom_mc)
{
removeEventListener(MouseEvent.CLICK, startGame);
game2 = new PreGame();
addChild(game2);
}
if (event.target == player_mc.pete_mc)
{
removeEventListener(MouseEvent.CLICK, startGame);
game = new PirGame();
addChild(game);
}
if(event.target == player_mc.sam_mc)
{
removeEventListener(MouseEvent.CLICK, startGame);
game3 = new SupGame();
addChild(game3);
}
}
public function gameOver():void
{
removeChild(game);
game = null;
stage.addEventListener(MouseEvent.CLICK, startGame);
}
}
}
Here's the PirGame document class code:
package com.usmanzubairi.theAges
{
import flash.utils.Timer;
import flash.events.*;
import flash.display.*;
import flash.geom.Matrix;
import flash.net.SharedObject;
public class PirGame extends MovieClip
{
public function PirGame()
{
addEventListener(MouseEvent.CLICK,rolling);
}
private function rolling (event:Event):void
{
if (event.target == MovieClip(root).roll_mc)
{
addChild(roll)
roll.visible = true;
runner_mc.visible = false;
roll.play();
}
}
}
}
Thanks.

If your roll_mc is in your PirGame symbol, and i think Pirgame class is well associated with the symbol, try modify your PirGame class a s follow:
package com.usmanzubairi.theAges
{
import flash.utils.Timer;
import flash.events.*;
import flash.display.*;
import flash.geom.Matrix;
import flash.net.SharedObject;
public class PirGame extends MovieClip
{
public function PirGame()
{
addEventListener(MouseEvent.CLICK,rolling);
}
private function rolling (event:Event):void
{
trace( event.target, roll_mc );
// change MovieClip(root).roll_mc to this.roll_mc as roll_mc is on this symbol and not on the root.
if( event.target == this.roll_mc )
{
trace( 'roll_mc clicked' );
addChild( roll )
roll.visible = true;
runner_mc.visible = false;
roll.play();
}
}
}
}
if you just want the roll_mc be clickable try the following:
package com.usmanzubairi.theAges
{
import flash.utils.Timer;
import flash.events.*;
import flash.display.*;
import flash.geom.Matrix;
import flash.net.SharedObject;
public class PirGame extends MovieClip
{
public function PirGame()
{
if( roll_mc ) roll_mc.addEventListener( MouseEvent.CLICK, rolling );
else addEventListener( Event.ADDED_TO_STAGE, _onStage );
}
private function _onStage( e:Event ):void
{
removeEventListener( Event.ADDED_TO_STAGE, _onStage );
roll_mc.addEventListener( MouseEvent.CLICK, rolling );
}
private function rolling( e:Event ):void
{
trace( 'roll_mc clicked' );
addChild( roll )
roll.visible = true;
runner_mc.visible = false;
roll.play();
}
}
}
if you don't have to re display the runner_mc you can remove it from the display list instead of make it not visible:
removeChild( runner_mc );

Related

Movement not working AS3

I'm currently working on a game, and am fairly new to AS3.
I'm stuck on the character movement: I was following a guide and ended up with the following as my code. When I test the game it just plays the character animation and I can't control it.
package {
import flash.display.Stage;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.utils.Proxy;
import flash.utils.flash_proxy;
dynamic public class KeyObject extends Proxy {
private static var stage:Stage;
private static var keysDown:Object;
public function KeyObject(stage:Stage) {
construct(stage);
}
public function construct(stage:Stage):void {
KeyObject.stage = stage;
keysDown = new Object();
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
}
flash_proxy override function getProperty(name:*):* {
return (name in Keyboard) ? Keyboard[name] : -1;
}
public function isDown(keyCode:uint):Boolean {
return Boolean(keyCode in keysDown);
}
public function deconstruct():void {
stage.removeEventListener(KeyboardEvent.KEY_DOWN,keyPressed);
stage.removeEventListener(KeyboardEvent.KEY_UP, keyReleased);
keysDown = new Object();
KeyObject.stage = null;
}
private function keyPressed(evt:KeyboardEvent):void {
keysDown[evt.keyCode] = true;
}
private function keyReleased(evt:KeyboardEvent):void {
delete keysDown[evt.keyCode];
}
}
}
package {
import flash.display.Sprite
import flash.events.Event;
import KeyObject;
public class Main extends Sprite{
private var key:KeyObject;
public function Main() {
addEventListener(Event.ADDED_TO_STAGE,setupKeyObject);
}
function setupKeyObject(e:Event){
key = new KeyObject(stage);
stage.addEventListener(Event.ENTER_FRAME,movePlayer);
}
function movePlayer(e:Event){
if(key.isDown(key.LEFT)){
roy.x -= 5;
}
if(key.isDown(key.RIGHT)){
roy.x +=5;
}
if(roy.x<0){
roy.x = 0;
}
if(roy.x > (stage.stageWidth - player.width)){
roy.x = stage.stageWidth - player.width;
}
}
}
}

AS3 duplicated MovieClip

In my app I'm importing movieclips from library to the stage like this :
package {
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.ui.Keyboard;
import flash.ui.Mouse;
import flash.display.MovieClip;
public class MainTimeline extends MovieClip {
//Variabili
public var VFullscreen: int = 1;
//Import var
public var VTerminal: Terminal = new Terminal();
public var nTerminal:String;
public function MainTimeline(): void {
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
//Import
//Terminal
VTerminal.x = 288;
VTerminal.y = 384;
stage.addChild(VTerminal);
//Event Listeners
//addEventListener(MouseEvent.CLICK, fl_BringToFront);
VTerminal.addEventListener(MouseEvent.MOUSE_DOWN, fl_WindowDrag);
VTerminal.addEventListener(MouseEvent.MOUSE_UP, fl_WindowDrop);
}
//public functions
//Gestione Fullscreen
public function fl_Fullscreen(event: MouseEvent): void {
switch (VFullscreen) {
case 0:
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
VFullscreen = 1;
break;
case 1:
stage.displayState = StageDisplayState.NORMAL;
VFullscreen = 0;
break;
}
}
public function fl_FSCheck(event: Event): void {
if (stage.displayState == StageDisplayState.NORMAL) {
VFullscreen = 0;
}
if (stage.displayState == StageDisplayState.FULL_SCREEN_INTERACTIVE) {
VFullscreen = 1;
}
}
//Primo Piano Finestre
public function fl_BringToFront(event: MouseEvent): void {
this.addChild(event.currentTarget as DisplayObject);
}
public function fl_WindowDrag(event: MouseEvent): void {
event.currentTarget.startDrag();
nTerminal = event.currentTarget.name.toString();
trace(nTerminal);
}
public function fl_WindowDrop(event: MouseEvent): void {
event.currentTarget.stopDrag();
}
//Chiusura
public function fl_Close(event: MouseEvent): void {
stage.nativeWindow.close();
}
//Apertura/Chiusura Terminal
public function fl_Terminal(event: MouseEvent): void {
if (contains(VTerminal)) {
removeChild(VTerminal);
} else {
VTerminal.x = 288;
VTerminal.y = 320;
addChild(VTerminal);
}
}
}
}
But I've a strange bug that I've never seen. It had the same MC twice and, in the runtime, when i drag and drop it I can see 2 MC one named instance8 and one instance45. I don't know how to solve this.
Thanks in advance.
TERMINAL CLASS
package {
import flash.display.MovieClip;
import flash.events.*;
import flash.ui.Keyboard;
import flash.text.TextField;
public class Terminal extends MovieClip {
public var version: String = "Verison 0.0.1 a";
public function Terminal(event: Event) {
//Varie
nome.text = "terminal";
vOut.text = version;
//Animazioni
loader0.gotoAndPlay(1);
loader1.gotoAndPlay(25);
}
}
}
As far as I can see, the statement
//Primo Piano Finestre
public function fl_BringToFront(event: MouseEvent): void {
this.addChild(event.currentTarget as DisplayObject);
}
when the mouseDown and mouseUp event finished, the mouseEvent.click event will trigger, so you will get another instance

how to bring movie clip on front in as3

I have two movieclips one over other. using mouse click event I want to bring one of them in the front. It works 1 or 2 times then it just stops responding to mouse clicks. I don't know what is happening. I tried hard but could not get it work.
Here is my code for document class :
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.SimpleButton;
public class THREE2DP extends MovieClip {
public var page11:page1;
public var page22:page2;
public var scene11:scene1;
public var scene22:scene2;
public function THREE2DP() {
// constructor code
stop();
createscene();
createpage2();
createpage1();
this.addEventListener(Event.ENTER_FRAME, enterframehandler);
}
public function enterframehandler(e:Event):void
{
if(scene11.front)
{
bringToFront(page11);
scene22.front = false;
}
if(scene22.front)
{
bringToFront(page22);
scene11.front = false;
}
}
private function bringToFront(mcl:MovieClip)
{
mcl.parent.setChildIndex(mcl,mcl.parent.numChildren - 1);
}
public function createpage1()
{
page11 = new page1();
addChild(page11);
page11.x = 0;
page11.y = 0;
}
public function createpage2()
{
page22 = new page2();
addChild(page22);
page22.x = 0;
page22.y = 0;
}
public function createscene()
{
scene11 = new scene1();
addChild(scene11);
scene11.x = 0;
scene11.y = 635;
scene22 = new scene2();
addChild(scene22);
scene22.x = 400;
scene22.y = 635;
}
}
}
here is code for scene11 movieclip custom class
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.SimpleButton;
public class scene1 extends MovieClip {
public var front:Boolean = false;
public function scene1() {
// constructor code
stop();
this.addEventListener(MouseEvent.CLICK, clickhandler, false, 0, true);
}
public function clickhandler(event:MouseEvent): void
{
front = true;
}
}
}
code for scene22 custom class is
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.SimpleButton;
public class scene2 extends MovieClip {
public var front:Boolean = false;
public function scene2() {
// constructor code
stop();
this.addEventListener(MouseEvent.CLICK, clickhandler, false, 0, true);
}
public function clickhandler(event:MouseEvent):void
{
front = true;
}
}
}
Upon click on movieclips scene11 and scene22, movieclip page11 and page22 should come on front of stage respectively but that happens only once for each page, after that nothing changes.
my earlier logic for custom classwas faulty. took me 2 day. added mouse_down event to make it work.
i some how managed to do this right by changing custom class code to this
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.SimpleButton;
public class scene1 extends MovieClip {
public var front:Boolean = false;
public function scene1() {
// constructor code
stop();
this.addEventListener(MouseEvent.MOUSE_DOWN, presshandler, false, 0, true);
this.addEventListener(MouseEvent.CLICK, clickhandler, false, 0, true);
}
public function presshandler(event:MouseEvent): void
{
front = true;
}
public function clickhandler(event:MouseEvent): void
{
front = false;
}
}
}
also modified document class code by calling pagechange() function from enterframehandler() function for sake of simplicity
public function pagechange()
{
if (scene11.front && scene22.front == false)
{
bringToFront(page11);
}
if (scene22.front && scene11.front == false)
{
bringToFront(page22);
}
}
private function bringToFront(mcl:MovieClip)
{
mcl.parent.setChildIndex(mcl,mcl.parent.numChildren - 1);
}
Instead of using that bringToFront method, you could just readd page11 and page22 on stage with addChild(). addChild always adds a child on front of everything else in the parent.
public function enterframehandler(e:Event):void
{
if(scene11.front)
{
addChild(page11);
scene22.front = false;
}
if(scene22.front)
{
addChild(page22);
scene11.front = false;
}
}

Error #2025: ActionScript problems with programing

The problem is that every time I try to go on to the next scene backStory
it doesn't remove the child. I want to make it so that when the counter goes to
4 it will take it out and put in a new scene. Is there a way to fix this issue? I don't understand how I can switch scenes
I am creating a game and I get this error :
ArgumentError: Error #2025: The supplied DisplayObject must be a
child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at Runner/onEnterFrame()
package {
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFormat;
public class Runner extends MovieClip {
public var startPage:StartPage = new StartPage();
public var backStory1:BackStory1 = new BackStory1();
public var water:Water = new Water();
public function Runner() {
addChild(startPage);
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
function onEnterFrame(event:Event):void{
if(startPage.endStartPage == true){
removeChild(startPage);
addChild(backStory1);
startPage.endStartPage == false;
}
if(backStory1.backStory1End == true){ //in backstory1 the bool backstory1end is suppose to be true but it doesnt get to that point
removeChild(backStory1);
addChild(water);
startPage.endStartPage == false;
}
}
}
}
Backstory class
package {
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFormat;
public class BackStory1 extends MovieClip {
var backStory1End:Boolean = false;
var count:int = 0;
public function BackStory1() {
backStory1Text.text = "sssherro";
if (stage)
{
init(null);
}
else
{
addEventListener(Event.ADDED_TO_STAGE,init);
}
function init(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
nextButton.addEventListener(MouseEvent.MOUSE_DOWN,onButtonClick);
}
function onButtonClick(event:MouseEvent):void{
count++;
if(count == 1){
backStory1Text.text = "awesome1";
//backStory1End= true;
}
else if(count == 2){
backStory1Text.text = "awesome2";
}
else if(count == 3){
backStory1Text.text = "awesome3 leave game press";
}
else if(count == 4){
//backStory1Text.text = (String)(counter);
backStory1End = true;
}
}
}
}
}
Following line is wrong.
startPage.endStartPage == false;
Fix:
startPage.endStartPage = false;

hitTestObject in a saprate class

i am making a simple game. here is the problem i am facing, but first i will tell you my class structure.
(i am using flash cs5.5)
Enemy.as : this class is linked with a MovieClip(in library), having code of simple enemy movment and directions.
Hero.as : Linked with a MovieClip in library. Code of Hero simple Movment
EnemyManager.as : Creates new enemy Every 20 Second.
HeroManager.as : Creates Hero(Only Once, other functionality will be added later).
HittingManager.as : checks for collusions(Problem Here)
Now My Problem is in HittingManager.as class because i want to add HitTestObject Functionalty in this class. i will post code of 3 important classes. (EnemyManager.as, HeroManager.as, HittingManager.as )
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class HeroManager extends MovieClip
{
private var hManager:HittingManager = new HittingManager();
public static var hero:Hero = new Hero();
public function HeroManager()
{
addEventListener(Event.ADDED_TO_STAGE, added);
}
private function added(event:Event):void
{
trace("hero manager added");
}
}//class
}//package
Here is the code of EnemyManager.as class
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.sampler.Sample;
import flash.display.Sprite;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.sampler.NewObjectSample;
public class EnemyManager extends MovieClip
{
private var hManager:HittingManager = new HittingManager();
private var timer:Timer = new Timer(2000);
public static var hitting:Boolean = false;
public static var enemy:Enemy;
public function EnemyManager()
{
addEventListener(Event.ADDED_TO_STAGE, added);
}
public function addEnemy(newEnemy:Enemy):void
{
addChild(newEnemy);
hManager.registerEnemy(newEnemy);
}
private function added(event:Event):void
{
addEventListener(Event.ENTER_FRAME, update);
trace("added enemy manger");
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
}
private function onTimer(event:TimerEvent):void
{
enemy = new Enemy();
this.addEnemy(enemy);
}
private function update(event:Event):void
{
}
}
}
And here Hittest.as class (i have tried many techniqes but all in vain ) so i am leaving if statment empty
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class HittingManager extends MovieClip
{
private var eManager:EnemyManager;
private var hEnemy:Enemy = new Enemy();
private var _enemies:Array;
private var _hero:Hero;
public function HittingManager()
{
//trace("Hitting Manager working");
_enemies = [];
addEventListener(Event.ADDED_TO_STAGE, added);
}
public function registerEnemy(newEnemy:Enemy):void
{
_enemies.push(newEnemy);
}
public function registerHero():void
{
//trace("heroRegisterd");
_hero = HeroManager.hero;
addChild(_hero);
}
private function added(event:Event):void
{
if(!_hero)
{
this.registerHero();
}
trace("Hitting manger added");
addEventListener(Event.ENTER_FRAME, update);
}
private function update(event:Event):void
{
if(_hero)
{
for each( newEnemy:Enemy in _enemies)
{
if(_hero.hitTestObject(newEnemy) )
{
trace("Hitting")
}
}
}
}
}//class
}//package
The revision below gets your code working with as few changes as possible, however it is in no way an ideal solution.
You should probably refactor your code so that the enemy manager doesn't need a public static reference to the HittingManager
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class HeroManager extends MovieClip
{
public static var hero:Hero = new Hero();
public function HeroManager()
{
addEventListener(Event.ADDED_TO_STAGE, added);
}
private function added(event:Event):void
{
trace("hero manager added");
}
} //class
} //package
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.sampler.Sample;
import flash.display.Sprite;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.sampler.NewObjectSample;
public class EnemyManager extends MovieClip
{
public static var hManager:HittingManager;
private var timer:Timer = new Timer(2000);
public static var hitting:Boolean = false;
public static var enemy:Enemy;
public function EnemyManager()
{
addEventListener(Event.ADDED_TO_STAGE, added);
}
public function addEnemy(newEnemy:Enemy):void
{
addChild(newEnemy);
hManager.registerEnemy(newEnemy);
}
private function added(event:Event):void
{
addEventListener(Event.ENTER_FRAME, update);
trace("added enemy manger");
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
}
private function onTimer(event:TimerEvent):void
{
enemy = new Enemy();
this.addEnemy(enemy);
}
private function update(event:Event):void
{
}
}
}
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class HittingManager extends MovieClip
{
private var _enemies:Array;
private var _hero:Hero;
public function HittingManager()
{
//trace("Hitting Manager working");
_enemies = [];
addEventListener(Event.ADDED_TO_STAGE, added);
}
public function registerEnemy(newEnemy:Enemy):void
{
_enemies.push(newEnemy);
}
public function registerHero():void
{
//trace("heroRegisterd");
_hero = HeroManager.hero;
addChild(_hero);
}
private function added(event:Event):void
{
if (!_hero)
{
this.registerHero();
}
trace("Hitting manger added");
addEventListener(Event.ENTER_FRAME, update);
}
private function update(event:Event):void
{
if (_hero)
{
for each (var newEnemy:Enemy in _enemies)
{
if (_hero.hitTestObject(newEnemy))
{
trace("Hitting")
}
}
}
}
} //class
} //package
In your main document class, you should have something like:
var hittingManager:HittingManager = new HittingManager();
EnemyManager.hManager = hittingManager;
var enemyManager:EnemyManager = new EnemyManager();
var heroManager:HeroManager = new HeroManager();
addChild(heroManager);
addChild(enemyManager);
addChild(hittingManager);