Skip to main content
Participating Frequently
August 5, 2010
Answered

Tween fade-in problem

  • August 5, 2010
  • 2 replies
  • 947 views

Hi-

I am trying to get all sections (brought in  using UILoaders) of my website to fade in when clicked on. I started out  with making the main image load in when the user navigates to the site  and that works. However, when I try to apply it to the other sections,  it fades it but it stays faded part way.. it doesn't come to 100%  opacity. I can't figure out what the problem is. I'm posting my code  here. If someone can tell me what I'm doing wrong, and show me how to  fix it, that would be really helpful! Note: The part that isn't fading  in properly is "sectionLoader"; the "main_mc" part is the initial home  image and that works fine but when navigating back to home from another  page (using nav buttons), the same thing happens with it not loading  properly:

//Tween info

import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.events.Event;

//Main image fade in

content_mc.main_mc.addEventListener(Event.COMPLETE, fadeIn);
sectionLoader.addEventListener(Event.COMPLETE, fadeIn);
function fadeIn(e:Event):void
{
     var myAlphaTween:Tween = new Tween(content_mc.main_mc,"alpha",Regular.easeOut,0,1,1,true);
     var myAlphaTween2:Tween = new Tween(sectionLoader,"alpha",Regular.easeOut,0,1,1,true);
}

//LISTEN FOR CLICK OF BUTTONS

function moveContent(theXPosition:Number, theYPosition:Number, theSection:String):void
{
     trace("X: "+theXPosition);
     trace("Y: "+theYPosition);
     var myxTween:Tween = new Tween(content_mc,"x",Regular.easeOut,content_mc.x,theXPosition,1,true);
     var myyTween:Tween = new Tween(content_mc,"y",Regular.easeOut,content_mc.y,theYPosition,1,true);
     sectionLoader.source = theSection;
}

home_btn.addEventListener(MouseEvent.CLICK, homeClick);

function homeClick(e:MouseEvent):void
{
     trace("homeClick");
     moveContent(-2227.55,-706.95,null);
     nav_lines.x = 162.80;
     nav_lines.y = 151.35;
}

abt_btn.addEventListener(MouseEvent.CLICK, abtClick);

function abtClick(e:MouseEvent):void
{
     trace("abtClick");
     moveContent(440.70,-2652.90,"about.swf");
     nav_lines.x = 162.80;
     nav_lines.y = 177.35;
}

port_btn.addEventListener(MouseEvent.CLICK, portClick);

function portClick(e:MouseEvent):void
{
     trace("portClick");
     moveContent(440.70,735.10,"portfolio.swf");
     nav_lines.x = 162.80;
     nav_lines.y = 204.35;
}

res_btn.addEventListener(MouseEvent.CLICK, resClick);

function resClick(e:MouseEvent):void
{
     trace("resClick");
     moveContent(440.70,-358.60,"resume.swf");
     nav_lines.x = 162.80;
     nav_lines.y = 229.35;
}

con_btn.addEventListener(MouseEvent.CLICK, conClick);

function conClick(e:MouseEvent):void
{
     trace("conClick");
     moveContent(436.70,-1480.15,"contact.swf");
     nav_lines.x = 162.80;
     nav_lines.y = 256.35;
}

Any response would be greatly appreciated. Thanks!!


*Pooja*

This topic has been closed for replies.
Correct answer kglad

use:


//Tween info

import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.events.Event;

//Main image fade in

content_mc.main_mc.addEventListener(Event.COMPLETE, fadeIn);
sectionLoader.addEventListener(Event.COMPLETE, fadeIn);

var myAlphaTween:Tween;
var myAlphaTween2:Tween;

function fadeIn(e:Event):void {      myAlphaTween = new Tween(content_mc.main_mc,"alpha",Regular.easeOut,0,1,1,true);      myAlphaTween2 = new Tween(sectionLoader,"alpha",Regular.easeOut,0,1,1,true); } //LISTEN FOR CLICK OF BUTTONS var myxTween:Tween;
var myyTween:Tween;

function moveContent(theXPosition:Number, theYPosition:Number, theSection:String):void {      trace("X: "+theXPosition);      trace("Y: "+theYPosition);      myxTween = new Tween(content_mc,"x",Regular.easeOut,content_mc.x,theXPosition,1,true);      myyTween = new Tween(content_mc,"y",Regular.easeOut,content_mc.y,theYPosition,1,true);      sectionLoader.source = theSection; } home_btn.addEventListener(MouseEvent.CLICK, homeClick); function homeClick(e:MouseEvent):void {      trace("homeClick");      moveContent(-2227.55,-706.95,null);      nav_lines.x = 162.80;      nav_lines.y = 151.35; } abt_btn.addEventListener(MouseEvent.CLICK, abtClick); function abtClick(e:MouseEvent):void {      trace("abtClick");      moveContent(440.70,-2652.90,"about.swf");      nav_lines.x = 162.80;      nav_lines.y = 177.35; } port_btn.addEventListener(MouseEvent.CLICK, portClick); function portClick(e:MouseEvent):void {      trace("portClick");      moveContent(440.70,735.10,"portfolio.swf");      nav_lines.x = 162.80;      nav_lines.y = 204.35; } res_btn.addEventListener(MouseEvent.CLICK, resClick); function resClick(e:MouseEvent):void {      trace("resClick");      moveContent(440.70,-358.60,"resume.swf");      nav_lines.x = 162.80;      nav_lines.y = 229.35; } con_btn.addEventListener(MouseEvent.CLICK, conClick); function conClick(e:MouseEvent):void {      trace("conClick");      moveContent(436.70,-1480.15,"contact.swf");      nav_lines.x = 162.80;      nav_lines.y = 256.35; }

2 replies

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
August 6, 2010

use:


//Tween info

import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.events.Event;

//Main image fade in

content_mc.main_mc.addEventListener(Event.COMPLETE, fadeIn);
sectionLoader.addEventListener(Event.COMPLETE, fadeIn);

var myAlphaTween:Tween;
var myAlphaTween2:Tween;

function fadeIn(e:Event):void {      myAlphaTween = new Tween(content_mc.main_mc,"alpha",Regular.easeOut,0,1,1,true);      myAlphaTween2 = new Tween(sectionLoader,"alpha",Regular.easeOut,0,1,1,true); } //LISTEN FOR CLICK OF BUTTONS var myxTween:Tween;
var myyTween:Tween;

function moveContent(theXPosition:Number, theYPosition:Number, theSection:String):void {      trace("X: "+theXPosition);      trace("Y: "+theYPosition);      myxTween = new Tween(content_mc,"x",Regular.easeOut,content_mc.x,theXPosition,1,true);      myyTween = new Tween(content_mc,"y",Regular.easeOut,content_mc.y,theYPosition,1,true);      sectionLoader.source = theSection; } home_btn.addEventListener(MouseEvent.CLICK, homeClick); function homeClick(e:MouseEvent):void {      trace("homeClick");      moveContent(-2227.55,-706.95,null);      nav_lines.x = 162.80;      nav_lines.y = 151.35; } abt_btn.addEventListener(MouseEvent.CLICK, abtClick); function abtClick(e:MouseEvent):void {      trace("abtClick");      moveContent(440.70,-2652.90,"about.swf");      nav_lines.x = 162.80;      nav_lines.y = 177.35; } port_btn.addEventListener(MouseEvent.CLICK, portClick); function portClick(e:MouseEvent):void {      trace("portClick");      moveContent(440.70,735.10,"portfolio.swf");      nav_lines.x = 162.80;      nav_lines.y = 204.35; } res_btn.addEventListener(MouseEvent.CLICK, resClick); function resClick(e:MouseEvent):void {      trace("resClick");      moveContent(440.70,-358.60,"resume.swf");      nav_lines.x = 162.80;      nav_lines.y = 229.35; } con_btn.addEventListener(MouseEvent.CLICK, conClick); function conClick(e:MouseEvent):void {      trace("conClick");      moveContent(436.70,-1480.15,"contact.swf");      nav_lines.x = 162.80;      nav_lines.y = 256.35; }

psha85Author
Participating Frequently
August 6, 2010

works great.. thanks! =)

kglad
Community Expert
Community Expert
August 6, 2010

you're welcome.

kglad
Community Expert
Community Expert
August 6, 2010

don't make your tweens local to a function.  they can get gc'd before the tween completes.

psha85Author
Participating Frequently
August 6, 2010

So how exactly do i fix that? I'm new to AS so the more detail, the better. Thanks! =)