Results 1 to 5 of 5

Thread: Condensing My Code...

  1. #1
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Condensing My Code...

    It seems in my code I am repeating myself alot to just get simple actions to happen... Can anyone take a look and see if I can condense it down?

    Code:
    on (rollOver) {
    	_root.right1.colorTransformTo(30, 70, undefined, undefined, undefined, undefined, undefined, undefined, .1);
    	_root.right_text1.alphaTo(60, 1, "easeOutSine");
    	_root.right1.xSlideTo(335, 1);
    	_root.right2.xSlideTo(365, 1);
    	_root.right3.xSlideTo(395, 1);
    	_root.right4.xSlideTo(425, 1);
    	_root.right_text1.xSlideTo(710, 1);
    	_root.right_text2.xSlideTo(740, 1);
    	_root.right_text3.xSlideTo(770, 1);
    	_root.right_text4.xSlideTo(800, 1);
    	_root.rollOverSound.start()
    	}
    
    on (rollOut) {
    	_root.right1.colorTransformTo(100, 0, 100, 0, 100, 0, 100, 0, 2);
    	_root.right_text1.alphaTo(20, 2, "easeOutSine");
    	_root.right1.xSlideTo(_root.right1.originalX, 1);
    	_root.right2.xSlideTo(_root.right2.originalX, 1);
    	_root.right3.xSlideTo(_root.right3.originalX, 1);
    	_root.right4.xSlideTo(_root.right4.originalX, 1);
    	_root.right_text1.xSlideTo(_root.right_text1.originalX, 1);
    	_root.right_text2.xSlideTo(_root.right_text2.originalX, 1);
    	_root.right_text3.xSlideTo(_root.right_text3.originalX, 1);
    	_root.right_text4.xSlideTo(_root.right_text4.originalX, 1);
    }

  2. #2
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Not really, since each is doing something different.

    However, if you will be re-using the code in different spots, you can make them a function, attached to a button, and then just call the functions on the buttons when needed.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  3. #3
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Any chance you could show me on the code? :/

  4. #4
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Something like:

    Code:
    // this is the rollOver code.
    nameOfbtn.onRollOver = function(){
    //your rollOver code goes here
    }
    
    //This is the rollOut code
    nameOfbtn.onRollOut = function(){
    //Your rollOut codes here
    }
    Then just name your buttons: nameOfbtn (instance name).
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Bearing in mind that I know nothing of ActionScript, you should be able to use a for loop and ECMAScript's idea of "objects as associative arrays:"
    Code:
    on (rollOver) {
    	_root.right1.colorTransformTo(30, 70, undefined, undefined, undefined, undefined, undefined, undefined, .1);
    	_root.right_text1.alphaTo(60, 1, "easeOutSine");
    	for(var i = 1; i < 5; ++i) {
    		_root['right' + i].xSlideTo(305 + (30 * i), 1);
    		_root['right_text' + i].xSlideTo(680 + (30 * i), 1);
    	}
    	_root.rollOverSound.start()
    }
    
    on (rollOut) {
    	_root.right1.colorTransformTo(100, 0, 100, 0, 100, 0, 100, 0, 2);
    	_root.right_text1.alphaTo(20, 2, "easeOutSine");
    	for(var i = 1; i < 5; ++i) {
    		_root['right' + i].xSlideTo(_root['right' + i].originalX, 1);
    		_root['right_text' + i].xSlideTo(_root['right_text' + i].originalX, 1);
    	}
    }
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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