0

I'm trying to make simple shooting game with Fiat Multipla falling up to bottom of the screen. I have created function to generate falling multipla and within this function I have a problem.

The main issue is that after change of multideath status to 1 "Death" function does nothing even if It is kept with ENTER_FRAME. Child becomes invisible as I implemented it in multipla movieclip, but even after response from there with Death = 1, nothing happens.

I'm new to all this, I've met and solved few issues during programming, but here's my brickwall for now. Code's either failing completely or I don't know something that's obvious. As I said, I'm newbie.

Thanks a lot for help!

Here's the function:

import flash.events.Event;
import flash.desktop.NativeApplication;
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

Mouse.hide();
var velocity = 0;
var ammo = 6;
LGUI.LGUIammo.gotoAndStop(6);

var counter = 0;

function multiplarain()
{

var x1 = Math.ceil(Math.random() * 280);
var y1 = -200;
var random:Multipla = new Multipla();
var life = 265;
var multideath = 0;

random.x = 100 + x1;
random.y = y1
addChild(random);
random.gotoAndStop(1);
setChildIndex(random, +1);

addEventListener(Event.ENTER_FRAME, Death);
    function Death(event:Event):void
    {
        if(multideath >= 1)
        {
        removeEventListener(Event.ENTER_FRAME, Death);
        removeChild(random);
        }
    }

addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);

    function fl_EnterFrameHandler(event:Event):void
        {
            if(random.y >= 680)
            {
            removeEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler)
            removeChild(random);
            trace("rofl");
            }
        }

random.addEventListener(Event.ENTER_FRAME, fl_AnimateVertically);

    function fl_AnimateVertically(event:Event)
    {
        velocity = velocity + 0.000035;
        random.y += 1.5 + velocity;
    }

random.addEventListener(TouchEvent.TOUCH_TAP, fl_TapHandler);

    function fl_TapHandler(event:TouchEvent):void
    {
        counter = counter + 1;
        ammo -= 1;
    }

if(ammo == 6)
{
    LGUI.LGUIammo.gotoAndStop(6);
}       
if(ammo == 5)
{
    LGUI.LGUIammo.gotoAndStop(5);
}               
if(ammo == 4)
{
    LGUI.LGUIammo.gotoAndStop(4);
}
if(ammo == 3)
{
    LGUI.LGUIammo.gotoAndStop(3);
}
if(ammo == 2)
{
    LGUI.LGUIammo.gotoAndStop(2);
}
if(ammo == 1)
{
    LGUI.LGUIammo.gotoAndStop(1);
}
if(ammo <= 0)
{
    LGUI.LGUIammo.gotoAndStop(7);
}

HGUI.saved.text = counter;  
this.addEventListener( Event.ENTER_FRAME, handleCollision)

var kucyk = LGUI.LGUIlife.lifeitself;

function handleCollision(e:Event):void
{
    if (random.hitTestObject(LGUI))
    {
        kucyk = LGUI.LGUIlife.lifeitself;
        kucyk.width -= 0.1;
    }
    /*if (kucyk.width == 0.75)
        {
            trace("cycki");
            NativeApplication.nativeApplication.exit(); 
        }*/
    }
}

and here's multipla's movieclip in library code:

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
this.addEventListener(TouchEvent.TOUCH_TAP, fl_TapHandler2);

function fl_TapHandler2(event:TouchEvent):void
{
    this.gotoAndPlay(2);
}


addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);

function fl_EnterFrameHandler(event:Event):void
{
    if(this.currentFrame == 60)
    {
        this.visible = false;
        MovieClip(root).multideath = 1;
        trace(MovieClip(root).multideath);
        removeEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
        removeEventListener(Event.ENTER_FRAME, fl_TapHandler2);
    }
}
Liquid
  • 1
  • 3

1 Answers1

0

it's been like 10 years since I last time worked with AS2 but I'd guess that this Multipla sets the multideath property in the wrong place. If i remember corrctly, root is the top-most level (your application). So if your first code is not on the main timeline but in a movieclip that is on the main timeline it won't work. Try to put a trace into the Death function to see if the multideath is really changing there:

trace(multideath);

try this in the multipla code:

parent.multideath = 1;

instead of

MovieClip(root).multideath = 1;

And I'm asking myself why do you need so many enter frame listeners? You can have just one and combine all animations in one function.

Also you don't need to check for multideath on every frame, just remove the movieclip in a separate function:

function removeMultipla():void
{
  removeChild(random);
}

Just call this function from your Multipla instead of setting the multideath property:

parent.removeMultipla();
Philarmon
  • 1,796
  • 1
  • 10
  • 14