Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9037173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:11:04+00:00 2026-06-16T09:11:04+00:00

I am making a platforming game in which I must switch between colliding the

  • 0

I am making a platforming game in which I must switch between colliding the character between two Arrays (whiteBlocks and blackBlocks) as well as another Array (redBlocks) that is activated on button collision and is timed.

However, I am having trouble with the hitTest code I have used to ensure that I can use redBlocks as a platform as well as either whiteBlocks or blackBlocks at the same time. I was wandering if anyone could help me to have the redBlocks constantly active once the timer has been triggered and is not effective by switching between blackBlocks or whiteBlocks.

If you would like me to explain my problem in a clearer way I will do. Please note that I am quite new to actionscript and coding in general so apologies for errors I may make. I appreciate any help you can offer as I have been troubleshooting this for a while now.

import flash.events.KeyboardEvent;
import flash.geom.Point;
import flash.events.Event;
import flash.display.MovieClip
import flash.display.DisplayObject;


//PLAYER MOVEMENT
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyLIST);
stage.addEventListener(KeyboardEvent.KEY_UP, keyLIST);

manMC.positionPNT = new Point (manMC.x, manMC.y);

//track using loop and keypresses, not just keyEvent
var leftKeyDown:Boolean = false;
var rightKeyDown:Boolean = false;

function keyLIST (ke:KeyboardEvent) {

    //trace(ke.toString() );

    //1. work out where we're going from where we are now

    //characterPNT = new Point(manMC.x, manMC.y);

        //2. offset our destination point
        switch (ke.keyCode) {

        //LEFT
        case 37:

            trace(ke.type);
            leftKeyDown = (ke.type == "keyDown");

        break;

        //RIGHT
        case 39:

            //moveCharacter(manMC, "right");
            rightKeyDown = (ke.type == "keyDown");

        break;

        //87UP, 83DOWN

        //UP
        case 38:

            trace("true");

            manMC.jump();

        break;

        //DOWN
        case 83:



        break;

        default:

            //trace ("this key does nothing");

        break;
    }// close switch

}// end function keyLIST

function movementCallback (ev:Event):void {

    if (leftKeyDown == true) {

        moveCharacter(manMC, "left");

    }

    if (rightKeyDown == true) {

        moveCharacter(manMC, "right");
    }
}

addEventListener (Event.ENTER_FRAME, movementCallback);

//a new movement function
function moveCharacter(char:character, dir:String ):void {//datatype as void as it returns nothing

    //will need this
    //var characterPNT:Point; //moved to character class
    //maMC.positionPNT = new Point( manMC.x, manMC.y);

    //copy current poistion before offsetting with movement, speed and direction
    manMC.destinationPNT = manMC.positionPNT.clone();
    //characterPNT = new Point(manMC.x, manMC.y);

    //var colliding:Boolean;

    //do multiple collision detection here

    var offsetPNT:Point;//detecting the destination of the body points

    switch (dir) {

        case "left":

            //move PNT to left
            manMC.destinationPNT.x -= manMC.speedNUM;
            offsetPNT = manMC.leftarmPNT;

        break;

        case "right":

            //move PNT to right
            manMC.destinationPNT.x += manMC.speedNUM;
            offsetPNT = manMC.rightarmPNT;



        break;
    }

    //set to true of false by the function that returns a Boolean value
    var colliding:Boolean = multipleHitTest (manMC.positionPNT, manMC.destinationPNT, offsetPNT, activeArray);

    //trace(colliding);
    //trace ("moveMode: " + manMC.moveModeSTR);

    if (!colliding /*&& manMC.moveModeSTR != "falling"*/) { //may be more complex to control player movement when falling&jumping

        manMC.moveToPoint( manMC.destinationPNT );

        //manMC.x = manMC.destinationPNT.x;
        //manMC.y = manMC.destinationPNT.y;

        //always update position PNT when character is moved
        //manMC.positionPNT = manMC.destinationPNT.clone();//copies destination point 
    }
}


//Apply gravity at all times using a loop/callback
addEventListener(Event.ENTER_FRAME, gravityFUNC);

var gravityNUM:Number = new Number(10);

function gravityFUNC (ev:Event) {

    var falling:Boolean;

    var gravityPNT:Point = manMC.positionPNT.clone();
    //trace(manMC.positionPNT.y);

    gravityPNT.y += gravityNUM;
    //trace(gravityPNT.y);

    //EXPERIMENTAL
    gravityPNT.y -= manMC.verticalVelocityNUM;

    //decaying gravity, caping it at 0 to avoid negatives
    manMC.verticalVelocityNUM = Math.max ( 0, manMC.verticalVelocityNUM - gravityNUM);


    falling = !multipleHitTest (manMC.positionPNT, gravityPNT, manMC.feetPNT, activeArray);
    //trace("falling " + falling);

    if (falling == true) {
        //manMC.y = gravityPNT.y;
        manMC.moveToPoint(gravityPNT);

        //either jumping or falling
        if ( manMC.verticalVelocityNUM == 0) {

            manMC.moveModeSTR = "falling";

        }else {

            manMC.moveModeSTR = "jumping";
        }

    } else {

        manMC.moveModeSTR = "walking";

    }
}

//======================================================================



//======================================================================


//add when declared
//varobstacles:Array = new Array (block0MC, block1MC, block2MC);

//declared and then new instance
//var obstacles:Array;
//obstacles = new Array (block6MC);

//declares and create empty array
/*var obstacles:Array = new Array();
//push adds an item to the front of an array
obstacles.push (block0MC); // add instance names of display objects (or other data)
obstacles.push (block1MC);
obstacles.push (block2MC);
obstacles.push (block3MC);*/


//trace("length of list" + obstacles.length);
//trace(obstacles[0]); //access first element of array

//trace( block0MC["x"] );// acessing x property using different method

function multipleHitTest( position:Point, destination:Point, offset:Point, targets:Array):Boolean { //these are ARGUMENTS

    //track hittest true or false
    var returnBOOL:Boolean = new Boolean (false);

    // cap length of loop - ie.e how many iterations?
    var limit:int = new int ( targets.length );// obstacles.length is 3 items long


    //the "counter", increases or decreases each time
    var i:int;

    //chunks =
    //start counter at 0;
    // loop while counter is less than limit;
    // increment counter by 1 each looop;

    for( i=0; i<limit; i++) {


        //will access each item in array, as "i" is an integer
        //obstacles[1];

        //because it's targeted as a movieclip we can ask it's name

        //this is 'reference variable'
        //we are creating an 'alias' of the item in the list
        var testAgainstObject:DisplayObject = targets[i];



        //track direction
        var moveDirection:String;

        //only hit test things we're moving towards...
        if (position.x < destination.x) { //if we're moving right 

            moveDirection = new String( "right" );

        } else if (position.x > destination.x) {//else if we're moving left

            moveDirection = new String( "left" );

        }

        //
        if(

           (moveDirection == "right" && targets[i].x >= position.x && destination.x >= targets[i].x)
           ||//or
           (moveDirection == "left" && targets[i].x <= position.x && destination.x <= (targets[i].x + targets[i].width) )

           ) {//obstacle is to the right

            //  obstacle moving right
            // moving right

        }

        //create a copy of 'destination' 
        var offsetDestination:Point = destination.clone();

        //apply our offset provided by our character limbs
        offsetDestination.offset(offset.x, offset.y);

        //if point is colliding with list item
        //if( testAgainstObject.hitTestPoint (destination.x, destination.y) ) { //REMOVED FOR TESTING
        if( testAgainstObject.hitTestPoint (offsetDestination.x, offsetDestination.y) ) {

            //trace("collisiondetected " + targets[i].name);
            returnBOOL = true;

        } else {
            //trace("no collision");

            //do nothing if flase, as it would contradict a 'true' value set earlier in the loop

        }

    }

    return (returnBOOL); //tesing only
}


//declares and create empty array
var blackBlocks:Array = new Array();
//push adds an item to the front of an array
blackBlocks.push (block0MC); // add instance names of display objects (or other data)
blackBlocks.push (block1MC);
blackBlocks.push (blackbarrier);
blackBlocks.push (blackbarrier2);
blackBlocks.push (blackbarrier3);
blackBlocks.push (blackbarrier4);
blackBlocks.push (blackbarrier5);



var whiteBlocks:Array = new Array();
//push adds an item to the front of an array
whiteBlocks.push (block2MC);
whiteBlocks.push (block3MC);
whiteBlocks.push (whitebarrier);
whiteBlocks.push (whitebarrier2);
whiteBlocks.push (whitebarrier3);
whiteBlocks.push (whitebarrier4);
whiteBlocks.push (whitebarrier5);

var redBlocks:Array = new Array();
redBlocks.push (redblock1MC);



//var activeArray:Array = new Array (blackBlocks);

var activeArray:Array = blackBlocks;
//active.push (redblock1MC);



//Adds an event listener to the button component with the mouse click event.
//hide_btn.addEventListener(MouseEvent.CLICK, toggleBlocks);
//show_btn.addEventListener(MouseEvent.CLICK, showObject);
stage.addEventListener(KeyboardEvent.KEY_DOWN, toggleBlocks);



// start toggle blocks
function toggleBlocks (event:KeyboardEvent):void {
    var i:int = 0;
    var lim:int = activeArray.length;

    if(event.keyCode == Keyboard.SPACE){
    trace("Toggle Blocks");

    blocksVisibility( activeArray , false );

    if( activeArray == blackBlocks) { 
        activeArray = whiteBlocks;

    }else{ 

    activeArray = blackBlocks;



    }

    blocksVisibility( activeArray , true );

} // end IF



} // end toggle blocks

function blocksVisibility( arrARG:Array , visBOOL:Boolean ){

    var i:int = 0;
    var lim:int = arrARG.length;

    for( i=0; i<lim; i++) {
        arrARG[i].visible = visBOOL;
    }

}

blocksVisibility( this.whiteBlocks , false );
blocksVisibility( this.redBlocks , false );

//blocksVisibility( this.redBlocks , false );


//======== red block button ========


// on collision trigger button and make red platform appear

/*
var myTimer:Timer = new Timer(5000,1);
myTimer.addEventListener(TimerEvent.TIMER, timerListener);

function timerListener(e:TimerEvent):void {
    //logo_mc.x+=40;
    blocksVisibility( this.redBlocks , true );
    //redBlock1MC:Array = true;

    //activeArray:Array = redBlocks;
}

myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onComplete);
function onComplete(e:TimerEvent):void {
    //logo_mc.alpha=10;
    //logo_mc.x=20;
    blocksVisibility( this.redBlocks , false );
    //redBlock1MC:Array = false;

    //activeArray:Array = blackBlocks;
}

stage.addEventListener(KeyboardEvent.KEY_DOWN, onStart);

function onStart(e:KeyboardEvent):void {
    if (e.keyCode == 88){

    blocksVisibility( this.redBlocks , true );
    //redBlock1MC:Array = true;

    myTimer.start();
    //logo_mc.alpha=.1;
    //logo_mc.x=20;
}
} */





var myTimer:Timer = new Timer(10000, 1); // 1 second

myTimer.addEventListener(TimerEvent.TIMER, timedPlatform);
//myTimer.start();

function timedPlatform(event:TimerEvent):void {


trace("timedPlatform() called @ " + getTimer() + " ms");


blocksVisibility( this.redBlocks , false );

/*if (manMC.hitTestObject(redButton)){


trace("Start Timer");
myTimer.start();


blocksVisibility( this.redBlocks , true );

        activeArray = redBlocks;


} */
}



redButton.addEventListener(Event.ENTER_FRAME, startTimer);
function startTimer(event:Event):void{
//if (e.keyCode == 88){

//if (manMC, hitTest(redButton)) {

if (manMC.hitTestObject(redButton)) {


trace("Start Timer");
myTimer.start();


blocksVisibility( this.redBlocks , true );

activeArray = blackBlocks;
//activeArray = blackBlocks;



/*if( activeArray == blackBlocks) { 
        activeArray = redBlocks;
                activeArray = blackBlocks;


    }else{ 

    activeArray = blackBlocks;



    }*/





} 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:11:06+00:00Added an answer on June 16, 2026 at 9:11 am

    Instead of making activeArray a reference to whiteBlocks or blackBlocks, make it a separate Array object. Then, in toggleBlocks, you can

    1. remove all elements from activeArray
    2. add all elements from redBlocks to activeArray (optional depending on the current state)
    3. add all elements from whiteBlocks OR blackBlocks to activeArray

    This way activeArray will have all red blocks AND (all whiteBlocks OR all blackBlocks).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Making an adobe flex ui in which data that is calculated must use proprietary
Making a new shooter game here in the vein of Galaga (my fav shooter
Im making a simple rock paper scissors game and I need to use the
Making an uno game for a project. all 108 cards are located in a
Im making a login form for a webbased game, Styled it very pretty etc.
Making a game with OpenGL/GLUT and C++. I've heard the easiest way to manage
Making a simple program which will generate a multiple choice form. I have an
Making a game... More efficient to do this? if (37 in keysDown) { //left
Making game of life I need to a have a grid that is 30x20
Making a SMS App and it is going well so far, but ran into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.