Hello and welcome to our community! Is this your first visit?
Register
Results 1 to 6 of 6
  1. #1
    Enthusiast

    Join Date
    Apr 2008
    Location
    Sydney, Australia
    Posts
    1,240

    Flash coding CS4/AS3

    This should probably go in the flash section, but it's been rather dead lately, so...

    This code is made for snowflakes going down the screen, but I need it to go across horizontally. I've searched the code for a while, but I'm really a novice. Can anyone please help?

    Code:
    package
    {
    
    import flash.display.*;
    import flash.events.*;
     
    public class Snowflake extends MovieClip
    {
    
    private var xPos:Number = 0;
    private var yPos:Number = 0;
     
    private var xSpeed:Number = 0;
    private var ySpeed:Number = 0;
     
    private var radius:Number = 0;
     
    private var scale:Number = 0;
    private var alphaValue:Number = 0;
     
    private var maxHeight:Number = 0;
    private var maxWidth:Number = 0;
     
    public function Snowflake()
    {
    
    SetInitialProperties();
    
    }
     
    public function SetInitialProperties()
    {
    
    //Setting the various parameters that need tweaking
    xSpeed = .05 + Math.random()*.1;
    ySpeed = .1 + Math.random()*3;
    radius = .1 + Math.random()*2;
    scale = .01 + Math.random();
    alphaValue = .1 + Math.random();
     
    var stageObject:Stage = this.stage as Stage;
    maxWidth = stageObject.stageWidth;
    maxHeight = stageObject.stageHeight;
     
    this.x = Math.random()*maxWidth;
    this.y = Math.random()*maxHeight;
     
    xPos = this.x;
    yPos = this.y;
     
    this.scaleX = this.scaleY = scale;
    this.alpha = alphaValue;
     
    this.addEventListener(Event.ENTER_FRAME, MoveSnowFlake);
    
    }
     
    function MoveSnowFlake(e:Event)
    {
    
    xPos += xSpeed;
    yPos += ySpeed;
     
    this.x += radius*Math.cos(xPos);
    this.y += ySpeed;
     
    if (this.y - this.height > maxHeight)
    {
    
    this.y = -10 - this.height;
    this.x = Math.random()*maxWidth;
    
    }
    
    }
    
    }
    
    }

  2. #2
    Fanatic Enthusiast Niall's Avatar

    Join Date
    Aug 2007
    Posts
    3,298

    Re: Flash coding CS4/AS3

    Try changing this in MoveSnowFlake:

    Code:
    this.x += radius*Math.cos(xPos);
    this.y += ySpeed;
    To this:

    Code:
    this.x += xSpeed;
    this.y += radius*Math.sin(yPos);
    I haven't tested anything but I don't see why it wouldn't work. What exactly is this for anyway? You should probably learn how this all works, what you're asking for isn't complicated.

  3. #3
    Enthusiast

    Join Date
    Apr 2008
    Location
    Sydney, Australia
    Posts
    1,240

    Re: Flash coding CS4/AS3

    I've already tried that, and I tried it again, but it doesn't work. It's for a school project thing by the way and I don't have the time to totally learn the coding, but I can get though the basics if I'm supplied the code. This problem just baffles me.

    I got it from this side as well, it if give you any ideas.
    http://www.kirupa.com/developer/flashcs ... s4_pg1.htm

  4. #4
    Fanatic Enthusiast Niall's Avatar

    Join Date
    Aug 2007
    Posts
    3,298

    Re: Flash coding CS4/AS3

    Ah okay, it was pretty straightforward. All I did was swap anything to do with the x axis with the y axis, and vice versa. You'll see the changes I made, hope this helps - http://filebox.me/view/zcucv4p5j

    If you've got any more questions just let me know.

  5. #5
    Enthusiast

    Join Date
    Apr 2008
    Location
    Sydney, Australia
    Posts
    1,240

    Re: Flash coding CS4/AS3

    Perfect, thank you. I just didn't realize you would have to change all the x and y values, but it would just be a line or two. Thanks, you've helped a lot.

  6. #6
    Tim
    Tim is offline
    Fanatic Enthusiast Tim's Avatar


    Join Date
    Apr 2009
    Location
    Sydney, Australia
    Posts
    2,857

    Re: Flash coding CS4/AS3

    Problem solved. If you want this unlocked, send a PM my way Hobden.


 

Posting Permissions

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