ActionScript: Move faded bars randomly across the X axis?

  • Johan007
  • Guru
  • Guru
  • User avatar
  • Posts: 1080
  • Loc: Aldershot, UK

Post 3+ Months Ago

I am new to action script. I am working on some faded vertical bars that I want to randomly appear and move left to right randomly across the X axis. Kind of like a film effect.

So far I have done: (source: http://www.sitepoint.com/print/flash-anthology-3 )

1. Draw a simple bar down the screen
2. Convert it to a movie clip symbol named Scripted_Animation .Position the symbol instance on the stage at (0, 0), and name the instance scripted_animation.
3. With the Actions Panel open and the first frame of the main timeline selected, add the following code:

Code: [ Select ]
var endX = scripted_animation._x + 100;
var endY = scripted_animation._y + 0;
var stepX = (endX - scripted_animation._x) / 10;
var stepY = (endY - scripted_animation._y) / 1;

scripted_animation.onEnterFrame = function ()
{
if (this._x < endX) this._x += stepX;
if (this._y < endY) this._y += stepY;
};
  1. var endX = scripted_animation._x + 100;
  2. var endY = scripted_animation._y + 0;
  3. var stepX = (endX - scripted_animation._x) / 10;
  4. var stepY = (endY - scripted_animation._y) / 1;
  5. scripted_animation.onEnterFrame = function ()
  6. {
  7. if (this._x < endX) this._x += stepX;
  8. if (this._y < endY) this._y += stepY;
  9. };


Now I need to add script for the image to start from a random point on the the X axis and NOT just (0, 0)! any idea?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • merz
  • Newbie
  • Newbie
  • merz
  • Posts: 5

Post 3+ Months Ago

Well the code below gives the scripted_animation object a randomized strand X and Y.
Math.random(); returns an int between 0.01 and 1, which would meen that if scripted_animation is located at the cord (0, 0) the new X cord would be between 1 and 100. As for the Y, it will always be 0.
Hope this answers your question, otherwise you msg again and I will do my best to help :wink: helo

Code: [ Select ]
var RandX = (scripted_animation._x + 100)*Math.random();
var RandY = (scripted_animation._y)*Math.random();
scripted_animation._x = RandX;
scripted_animation._y = RandY;
  1. var RandX = (scripted_animation._x + 100)*Math.random();
  2. var RandY = (scripted_animation._y)*Math.random();
  3. scripted_animation._x = RandX;
  4. scripted_animation._y = RandY;
[/url]

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 12 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.