How to pause 'if collision' in Flash CS5?

This is the collision

   if(blue2.hitTestObject(_helicopter))

            {
                trace("YOU HIT THE BLOCK!");
                ihit = true;
                _helicopter.x = 76;
                _helicopter.y = 217;
            }

Is it possible to add the pause function in that collision code^? Is so, what do I write there please? Thank you!

Answers


Pause is a bit difficult to interpret in your context.

For instance, if your game had an enter frame handler you could stop all game animation for a period of time. Or, maybe you want to freeze a "You hit the block!" message for a period of time while background animations still ran.

One approach is to use a timer. It's asynchronous, but the end result here is that a function is called after a period of time (milliseconds).

In this example, 5-seconds after your code is executed, an anonymous function responds that the time is up:

// needed imports:
import flash.events.TimerEvent;
import flash.utils.Timer;

if (blue2.hitTestObject(_helicopter))
{
    trace("YOU HIT THE BLOCK!");
    ihit = true;
    _helicopter.x = 76;
    _helicopter.y = 217;

    var timer:Timer = new Timer(5000); // 5-seconds
    timer.addEventListener(TimerEvent.TIMER, function(event:TimerEvent):void
    {
        timer.reset();
        timer.removeEventListener(TimerEvent.TIMER, arguments.callee);
        trace("5-seconds after hitting the block.");
    });
    timer.start();
}

If you don't like the anonymous function, you could implement it as:

// needed imports:
import flash.events.TimerEvent;
import flash.utils.Timer;

if (blue2.hitTestObject(_helicopter))
{
    trace("YOU HIT THE BLOCK!");
    ihit = true;
    _helicopter.x = 76;
    _helicopter.y = 217;

    var timer:Timer = new Timer(5000); // 5-seconds
    timer.addEventListener(TimerEvent.TIMER, collisionWaitHandler);
    timer.start();
}

// ... later in its own function:

protected function collisionWaitHandler(event:TimerEvent):void
{
    var timer:Timer = Timer(event.currentTarget);
    timer.reset();
    timer.removeEventListener(TimerEvent.TIMER, collisionWaitHandler);

    trace("5-seconds after hitting the block.");
}

Need Your Help

Scrapy does not follow the Request url

url request scrapy

Following is the code. Basically, I am scraping movie info. from IMDB.com. But somehow the Request doesn't scrap the url, which is in the object "addr". The "print" I put into the parse_item2 simpl...