A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: variable for x, y position?

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    3

    variable for x, y position?

    Hi, I have bought some code to make a starry night in my animation but I need to make this either only appear inside a movie clip, or on a certain part of the stage, can anyone tell me how to alter the below code so I can do this? do you I need to add in some x, y coordinates?

    Thanks!


    import mx.transitions.Tween;
    import mx.transitions.easing.*;

    var maxStars:Number = 25;
    var minSize:Number = 50;
    var maxSize:Number = 115;
    var maxDuration:Number = 3;
    var minDuration:Number = 1;
    var windowWidth:Number = 100;
    var windowHeight:Number = 100;

    var stars:Array = new Array(maxStars);
    var starsClip:Array = new Array(maxStars);
    var starsTweenX:Array = new Array(maxStars);
    var starsTweenY:Array = new Array(maxStars);

    for (var init:Number = 0; init < maxStars; init++) {
    /* Sets the duration for the star to appear */
    var duration = Math.random() * (maxDuration - minDuration) + minDuration;

    /* Attaches the Star movieclp to the Stage and sets its parameters */
    _root.attachMovie("Star", "myStar"+init, _root.getNextHighestDepth());
    _root["myStar"+init]._x = Math.random() * windowWidth;
    _root["myStar"+init]._y = Math.random() * windowHeight;
    _root["myStar"+init]._xscale = _root["myStar"+init]._yscale = Math.random() * (maxSize - minSize) + minSize;

    /* Sets the twinkling of the stars */
    starsTweenX[init] = new Tween(_root["myStar"+init], "_xscale", None.easeNone, _root["myStar"+init]._xscale, 0, duration, true);
    starsTweenY[init] = new Tween(_root["myStar"+init], "_yscale", None.easeNone, _root["myStar"+init]._yscale, 0, duration, true);

    /* Resets the stars once they've faded out */
    starsTweenX[init].onMotionFinished = function() {
    if (this.obj._xscale == 0) {
    this.obj._x = Math.random() * windowWidth;
    }
    this.yoyo();
    }
    starsTweenY[init].onMotionFinished = function() {
    if (this.obj._yscale == 0) {
    this.obj._y = Math.random() * windowWidth;
    }
    this.yoyo();
    }
    }

  2. #2
    Member
    Join Date
    Nov 2009
    Location
    Philadelphia
    Posts
    40
    In this section of your code...
    PHP Code:
    /* Attaches the Star movieclp to the Stage and sets its parameters */
    _root.attachMovie("Star""myStar"+init_root.getNextHighestDepth()); 
    _root["myStar"+init]._x Math.random() * windowWidth;
    _root["myStar"+init]._y Math.random() * windowHeight;
    _root["myStar"+init]._xscale _root["myStar"+init]._yscale Math.random() * (maxSize minSize) + minSize
    PHP Code:
    Math.random() * windowWidth 
    sets the X and Y positon of the clip... change the random value to what you need for example:

    PHP Code:
    Math.random() * 100 
    will give you a set of random numbers between 0 and 100...
    PHP Code:
    (Math.random() * 100)+50 
    will give you a set of random numbers between 50 and 150... get it?
    - Nick Stanziani

    pls support: www.whowantsacookie.com

    My site: pebcak

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center