Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Basic Rectangle Transparency

    Hi. I'm trying to do an assignment, and I can't seem to figure out how to get the last part. Here are the directions:

    "Using a for loop, fill the array with 10 rectangles. Then using forEach, change the alpha value of each rectangle so that the rectangle on the left is solid and the last rectangle on the right is transparent"

    Here is what I have:

    public function forEachArray():void {
    var flArray2:Array = new Array();
    for (var i:int=0; i<10; i++) {
    var xpos:int = 30 + (i*30);
    var mySprite:Sprite = new Sprite();
    mySprite.graphics.beginFill(0xff0000);
    mySprite.graphics.lineStyle(1);
    mySprite.graphics.drawRect(xpos, 30, 30, 85);
    mySprite.graphics.endFill();
    addChild(mySprite);
    flArray2.push(mySprite);
    }
    function arrayAlpha(element:Sprite, index:int, a:Array):void {
    element.alpha = (index*.25);
    }
    flArray2.forEach(arrayAlpha);

    }


    Yes, it must be done in this ridiculous way, and all I have left to do is make it solid on the left, fading to transparent. I have it opposite. Any help please?

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    This is AS3 right?
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Were you required to use AS3? Some things in AS3 are easier and some are easier in AS2. In this case it might be easier in AS2 as its not so object oriented.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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