Skip to main content
New Participant
July 22, 2018
Answered

drawing symbols on a map - how to delay each placement?

  • July 22, 2018
  • 1 reply
  • 366 views

Hi,

yesterday I gave Flash (AS3) a chance to draw me symbols on a map. The coordinates of which derive from a simple external file.

Since it is my first trial with Flash I am already quite happy with the current outcome. What puzzles me however, how I could delay the placement of the symbols so that they will be displayed on stage one after the other rather then altogether. I tried timers such as "setTimeout" or "tweener" (at a position see below) with no success. There is a delay but only before all symbols are displayed still at once. Most probably a very silly thing...

Structurally this happens:

--------------------------------------------------------

load coordinates from file into an array line by line (x/y coordinates)

start loop through array

retrieve X- and Y coordinates

instantiate shape

define shape-size, -color, -position

<-- TIMER!?

    addchild (shape)

end loop

--------------------------------------------------------

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

Let's supose you have a vector (can be a regular array) representing the coordinates you got from the external source and a libray symbol with a linkage name "Pin".

You set a interval and at each interval you pick a coord from the vector or array by incrementing a numeric variable by one.

Try this:

import flash.geom.Point;

import flash.utils.setInterval;

import flash.utils.clearInterval;

var coords:Vector.<Point> = new <Point>[new Point(10, 50), new Point(75, 20), new Point(240, 360)];

var delay:Number = 1;

var count:uint = 0;

var interval:uint = setInterval(function()

{

     if (count == coords.length - 1)

          clearInterval(interval);

     var pin:Pin = new Pin();

     pin.x = coords[count].x;

     pin.y = coords[count].y;

     addChild(pin);

     count++;

}, delay * 1000);

I hope this helps.

Regards,

JC

1 reply

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
July 22, 2018

Hi.

Let's supose you have a vector (can be a regular array) representing the coordinates you got from the external source and a libray symbol with a linkage name "Pin".

You set a interval and at each interval you pick a coord from the vector or array by incrementing a numeric variable by one.

Try this:

import flash.geom.Point;

import flash.utils.setInterval;

import flash.utils.clearInterval;

var coords:Vector.<Point> = new <Point>[new Point(10, 50), new Point(75, 20), new Point(240, 360)];

var delay:Number = 1;

var count:uint = 0;

var interval:uint = setInterval(function()

{

     if (count == coords.length - 1)

          clearInterval(interval);

     var pin:Pin = new Pin();

     pin.x = coords[count].x;

     pin.y = coords[count].y;

     addChild(pin);

     count++;

}, delay * 1000);

I hope this helps.

Regards,

JC

New Participant
July 23, 2018

Hi João,

it helped!! Although quite a tricky approach with respect to other programs.

Thanks a lot and have a nice day

Regards

Thomas

JoãoCésar17023019
Community Expert
Community Expert
July 23, 2018

You're welcome!