A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: function fade not fading

  1. #1
    twisted eye
    Join Date
    Dec 2001
    Location
    london, england
    Posts
    134

    function fade not fading

    Hi

    Can someone tell me whats wrong with my code. I dont know wether its because i have been looking at it for far too long that I cant see anything wrong!!! Please help.

    the function is supposed to fade targetA to its destination before fading targetB to its destination.

    Any takers?????

    function fadeContent(targetA, targetB, destinationA, destinationB, fadespeed) {
    rate = fadespeed;
    targetA.onEnterFrame = function() {
    rate = rate*1;
    this._alpha += Math.round((destinationA-this._alpha)/rate);
    if (this._alpha == destinationA) {
    targetB.onEnterFrame = function() {
    this._alpha += Math.round((destinationB-this._alpha)/rate);
    if (this._alpha == destinationB) {
    delete this.onEnterFrame;
    }
    };
    }
    };
    }
    everything takes time, of which i have none.

  2. #2
    Novemberain Master
    Join Date
    Sep 2004
    Location
    Void
    Posts
    390
    Code:
    function fadeContent (targetA, targetB, destinationA, destinationB, fadespeed)
    {
    	// Do not forget to use var keyword to create local variables. It is good (even essential) coding technique.
    	var rate = fadespeed;
    	targetA.onEnterFrame = function ()
    	{
    		// Do you really need the line below?
    		rate = rate * 1;
    		this._alpha += Math.round ((destinationA - this._alpha) / rate);
    		if (this._alpha == destinationA)
    		{
    			targetB.onEnterFrame = function ()
    			{
    				this._alpha += Math.round ((destinationB - this._alpha) / rate);
    				if (this._alpha == destinationB)
    				{
    					// Okay, you've deleted targetB's onEnterFrame. What about targetA's one?
    					delete this.onEnterFrame;
    				}
    			};
    		}
    	};
    }
    I've commented your code. Take a look at it. Maybe this would help you.


    Never give up...

  3. #3
    twisted eye
    Join Date
    Dec 2001
    Location
    london, england
    Posts
    134
    Hey Unsteady

    Cheers for that been looking at the screen too long. I managed to get it working by changing it a bit.

    have a look and let me know what you think

    function fadeContent(targetA, targetB, destinationA, destinationB, fadespeed) {
    targetA.onEnterFrame = function() {
    var targAa = destinationA-targetA._alpha;
    targAb = (targAb+targAa)/fadespeed;
    targetA._alpha += targAb;
    if (Math.round(targAa) == 0 && Math.round(targAb) == 0) {
    delete targetA.onEnterFrame;
    targetB.onEnterFrame = function() {
    var targBa = destinationB-targetB._alpha;
    targBb = (targBb+targBa)/fadespeed;
    targetB._alpha += targBb;
    if (Math.round(targBa) == 0 && Math.round(targBb) == 0) {
    delete targetB.onEnterFrame;
    }
    };
    }
    };
    }

    cheers for you help
    everything takes time, of which i have none.

  4. #4
    Novemberain Master
    Join Date
    Sep 2004
    Location
    Void
    Posts
    390
    Code:
    function fadeContent (targetA, targetB, destinationA, destinationB, fadespeed)
    {
    	targetA.onEnterFrame = function ()
    	{
    		var targAa = destinationA - targetA._alpha;
    		// Use var in the line below, too :) As you did above
    		targAb = (targAb + targAa) / fadespeed;
    		targetA._alpha += targAb;
    		if (Math.round (targAa) == 0 && Math.round (targAb) == 0)
    		{
    			delete targetA.onEnterFrame;
    			targetB.onEnterFrame = function ()
    			{
    				var targBa = destinationB - targetB._alpha;
    				// Use var in the line below, too :) As you did above
    				targBb = (targBb + targBa) / fadespeed;
    				targetB._alpha += targBb;
    				// The line above can be written this way: if(!Math.round(targBa) && !Math.round(targBb))
    				if (Math.round(targBa) == 0 && Math.round (targBb) == 0)
    				{
    					delete targetB.onEnterFrame;
    				}
    			}
    		}
    	}
    }


    Never give up...

  5. #5
    twisted eye
    Join Date
    Dec 2001
    Location
    london, england
    Posts
    134
    thanks for that...

    can I just ask one more question which doesnt relate to the above.

    How do you put the code on this site with a line above and below the code and the title 'code', and all in blue. It makes posting look nice and tidy. thanks!!!
    everything takes time, of which i have none.

  6. #6
    Novemberain Master
    Join Date
    Sep 2004
    Location
    Void
    Posts
    390
    When you type your post you can see # button on the panel (to the left of PHP button). Click it, enter whatever you want (for example, "a") and when board system inserts pseudo-html code into your message, delete everything you've put between starting and ending code tags and insert your code.

    Or you can use pseudo-html "code" tag directly:
    Code:
    [ code ]
    // Enter your code here
    [ / code ]
    Note: whitespace characters in "code" tag in example above must be removed. I've inserted them just to avoid replacement by the board system.


    Never give up...

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