AS3: Tween from one MovieClip to Another

Hi!
As the title implies, I'm trying to use ActionScript 3 to tween from one movieclip to another based on an external event.
I'm currently using two "Tween" objects to adjust alpha values. The first tweens-out the previous movieclip, and the second tweens-in the current movieclip. Code follows, with headers included for completeness:
// headers
     import fl.transitions.Tween;
     import fl.transitions.easing.*;
// tweens
     var MOVIECLIP1_out:Tween = new Tween(MOVIECLIP1, "alpha", Regular.easeOut, 1, 0, 3, true);
          var MOVIECLIP2_in:Tween = new Tween(MOVIECLIP2, "alpha", Regular.easeIn, 0, 1, 3, true);
My issue, as you might suspect, is that the transition doesn't look right. The previous clip tweens to a blank white screen, and then the second is brought in. I need the tweens to overlap, as they would with a timeline-based tween.
How do I remedy this? My solution was to create a loop, from 0 to 1 incrementing by 0.2, and setting the respective alpha values to increase and decrease. I also planned to set the time for each tween to one-tenth (0.1) of a second:
    var _out1: 1
    var _out2: 0.8
    var _in1: 0
    var _in2: 0.2
while (_in1 <= 1)
    var MOVIECLIP1_out:Tween = new Tween(MOVIECLIP1, "alpha", Regular.easeout, _out1, _out2, 0.1, true);
    var MOVIECLIP2_in:Tween = new Tween(MOVIECLIP2, "alpha", Regular.easeIn, _in1, _in2, 0.1, true);
    _out1 = _out1 - 0.2;
    _out2 = _out2 - 0.2;
    _in1 = _in1 + 0.2;
    _in2 = _in2 + 0.2;
This would result in ten total tweens, over one full second, as follows:
time : Clip : alpha change
0.1 : MOVIECLIP1 : 1 to 0.8
0.1 : MOVIECLIP2 : 0 to 0.2
0.1 : MOVIECLIP1 : 0.8 to 0.6
0.1 : MOVIECLIP2 : 0.2 to 0.4
0.1 : MOVIECLIP1 : 0.6 to 0.4
0.1 : MOVIECLIP2 : 0.4 to 0.6
0.1 : MOVIECLIP1 : 0.4 to 0.2
0.1 : MOVIECLIP2 : 0.6 to 0.8
0.1 : MOVIECLIP1 : 0.2 to 0
0.1 : MOVIECLIP2 : 0.8 to 1
And the transition is complete.
I feel that there must be a smarter way to accomplish this task. Do I have my head screwed on right here? Any suggestions?

I think that I posted this in the wrong forum... maybe an admin can move this to the AS3 section?
Anyway, in the absence of an answer, I coded the following, and it works pretty well. I had to round the alpha values to the tenths place.
YOURBUTTON.addEventListener
  MouseEvent.MOUSE_OVER,
  function(evt:MouseEvent):void
    var _out1:Number = 1;
    var _out2:Number = 0.8;
    var _in1:Number = 0;
    var _in2:Number = 0.2;
while (_in2 <= 1)
    var MOVIECLIP1_out:Tween = new Tween(MOVIECLIP1, "alpha", Regular.easeOut, _out1, _out2, 1, true);
    var MOVIECLIP2_in:Tween = new Tween(MOVIECLIP2, "alpha", Regular.easeIn, _in1, _in2, 1, true);
    _out1 = int((_out1 - 0.2 + 0.05)*10)/10;
    _out2 = int((_out2 - 0.2 + 0.05)*10)/10;
    _in1 = int((_in1 + 0.2 + 0.05)*10)/10;
    _in2 = int((_in2 + 0.2 + 0.05)*10)/10;

Similar Messages

  • AS3: Alpha Tween from one MovieClip to Another

    Hi folks,
    Using AS3, how do I create an alpha tween from one movie clip to another?
    My thinking is that I can't use the timeline, because the fade is variable and event driven; e.g., the user clicks on one of many pics, and the stage alpha tweens from the current to the clicked. But maybe I'm wrong.
    Any suggestions?
    tyvm!

    Look into the AS3 Tween class. If you need to coordinate the tweening based on one tweening out before the other tweens in, then you will also want to look into having event listeners in play to detect when the tween finishes.
    Here's a link to a sample file I created to help demo things:
    http://www.nedwebs.com/Flash/AS3_Tween_Images.fla

  • OBIEE 11g How to pass variable from one prompt to another prompt in dashboard page.

      How to pass variable from one prompt to another prompt in dashboard page.
    I have two prompt in dashboard page as below.
    Reporttype
    prompt: values(Accounting, Operational) Note: values stored as
    presentation variable and they are not coming from table.
    Date prompt values (Account_date, Operation_date)
    Note:values are coming from dim_date table.  
    Now the task is When user select First
    Prompt value  “Accounting” Then in the
    second prompt should display only Accounting_dates , if user select “operational”
    and it should display only operation_dates in second prompt.
    In order to solve this issue I made the
    first prompt “Reporttype” values(Accounting, Operational) as presentation
    values (custom specific values) and default presentation value is accounting.
    In second prompt Date are coming from
    dim_date table and I selected Sql results as shown below.
    SELECT case when '@{Reporttype}'='Accounting'
    then "Dates (Receipts)"."Acct Year"
    else "Dates (Receipts)"."Ops
    Year"  End  FROM "Receipts"
    Issue: Presentation variable value is not
    changing in sql when user select “operation” and second prompt always shows
    acct year in second prompt.
    For testing pupose I kept this presentation
    variable in text object of dashboard and values are changing there, but not in
    second prompt sql.
    Please suggest the solution.

    You will want to use the MoveClipLoader class (using its loadClip() and addListener() methods) rather than loadMovie so that you can wait for the file to load before you try to access anything in it.  You can create an empty movieclip to load the swf into, and in that way the loaded file can be targeted using the empty movieclip instance name.

  • Function to fade audio smoothly from one level to another in AS2

    Greetings all.
    I'm a newcomer to Actionscript programming and trying to modify a Flash site template downloaded from TemplateMonster.com (which is an AS2 template).  I've almost succeeded at what I need to do but have run into a couple of brick walls.  One is that I've added a video player to the site and need to make the background music track smoothly fade out when the video starts and fade back in when it ends (or is stopped).  I set up a listener object for the video player that works.  It's the smooth fade of audio levels that doesn't.
    I found an excellent thread from last year (http://forums.adobe.com/message/3236495) in which kglad address the issue of fading audio from one level to another.  Since TemplateMonster's templates set up a master movie clip and then load pages to play within it, and I need to call the function from within the pages, I tried setting it up as a global function.
    So when the overall site initializes, I have this:
    this.createEmptyMovieClip("mcMusictrackHolder", this.getNextHighestDepth());
    var sndAudio:Sound = new Sound(mcMusictrackHolder);
    var nMaxMusicVolume:Number = new Number(mcMusictrackHolder);
    nMaxMusicVolume = 30;
    sndAudio.attachSound("MusicTrack");
    sndAudio.setVolume(nMaxMusicVolume);
    sndAudio.start(0,9999);
    // Here is kglad's function converted to a global function
    _global.fadeSoundF = function(mc:MovieClip,s:Sound,vol:Number,sec:Number):Void
         trace("Getting here with sound at " + s.getVolume());
         clearInterval(mc.fadeI);
         var volumeInc:Number = vol-s.getVolume()/(10*sec);
         mc.fadeI=setInterval(fadeF,100,mc,s,volumeInc,vol);
         trace("Leaving with sound at " + s.getVolume());
    function fadeF(mc:MovieClip,s:Sound,inc:Number,endVol:Number):Void
         s.setVolume(s.getVolume()+inc);
         if(Math.abs(s.getVolume-endVol)<inc)
              clearInterval(mc.fadeI);
    Then within the page that contains the video player (a child of the above), I have this:
    var listenerObject:Object = new Object();
    var sCurrentState:String;
    listenerObject.stateChange = function(eventObject:Object):Void
    sCurrentState = my_FLVPlybk.state;
    if (sCurrentState == "playing")
      fadeSoundF(_root.mcMusictrackHolder,_root.sndAudio,0,1);
    else
      fadeSoundF(_root.mcMusictrackHolder,_root.sndAudio,_root.nMaxMusicVolume,1);
    my_FLVPlybk.addEventListener("stateChange", listenerObject);
    The listener object is working fine - so if instead of calling fadeSoundF I simply do _root.sndAudio.setvolume(0) to mute and _root.sndAudio.setvolume(30) to restore it works fine except that the volume changes abruptly instead of ramping.
    But obviously there's a problem with my effort to convert kglad's function to global and use it that way, because the trace statements tell me the audio is getting set to random levels.  It smoothly ramps all right - but tries to get to -472 or +8212 or other insane numbers.
    Any help with where I'm going wrong would be deeply appreciated.  Keep in mind that although I have some long-ago programming experience in other languages, this environment is completely alien to me and you can feel free to assume I'm completely ignorant.  What I've managed to piece together is largely pulled from online research, which is why there's probably an obvious glaring error in there.  Feel free to provide a response that assumes I know nothing.
    Best,
    Pete

    I added a few more traces.  Here's the new main page:
    this.createEmptyMovieClip("mcMusictrackHolder", this.getNextHighestDepth());
    var sndAudio:Sound = new Sound(mcMusictrackHolder);
    var nMaxMusicVolume:Number = 30;
    sndAudio.attachSound("MusicTrack");
    sndAudio.setVolume(nMaxMusicVolume);
    sndAudio.start(0,99999);
    _global.fadeSoundF = function(mc:MovieClip,s:Sound,vol:Number,sec:Number):Void
              trace("Getting here with level at " + sndAudio.getVolume());
              trace("asking to set it to " + vol + " in " + sec + " second(s).");
              clearInterval(mc.fadeI);
              var volumeInc:Number = vol-s.getVolume()/(10*sec);
              mc.fadeI=setInterval(fadeF,100,mc,s,volumeInc,vol);
              trace("Leaving with sound at " + sndAudio.getVolume());
              trace(" ");
    function fadeF(mc:MovieClip,s:Sound,inc:Number,endVol:Number):Void
              s.setVolume(s.getVolume()+inc);
              if(Math.abs(s.getVolume-endVol)<inc)
                        clearInterval(mc.fadeI);
    Here's sample trace output:
    Getting here with level at 30                  <---- this is on first visiting the page where the listener object initializes and asks it to ramp the audio from its
    asking to set it to 30 in 1 second(s).             current level to the same level (probably because the video is buffering or rewinding and that counts as a state change).
    Leaving with sound at 30
    Getting here with level at 111                <---- this is a second triggering of the function (probably because the video is STOPPED and that counts as a
    asking to set it to 30 in 1 second(s).            state change after buffering).  As of yet the video hasn't been asked to play.
    Leaving with sound at 111
    Getting here with level at 3765               <---- This is what happens when the video is asked to play; since it is asking to leave the level at 30 I'm guessing it is buffering
    asking to set it to 30 in 1 second(s).              again but not playing yet, which is why it's still being asked to set the background to 30 instead of 0.
    Leaving with sound at 3765
    Getting here with level at 3765                <---- NOW the video is actually playing, so it asks to set the background audio to 0.
    asking to set it to 0 in 1 second(s).
    Leaving with sound at 3765
    Getting here with level at -41740             <---- ... and I hit STOP, which generates a request to bring the background audio back to 30.
    asking to set it to 30 in 1 second(s).
    Leaving with sound at -41740
    I should probably replace the if/else on the video player page with a switch/case so the function ONLY gets called when playback actually stops and starts, and doesn't get triggered for every state change.  But I think I still have an error in here someplace...
    Many thanks to kglad for your help!
    Pete

  • Passing variables from one swf to another

    I am facing problem to pass variable from one swf to another.
    I am using loadMovie to load another swf. how can I pass a variable
    value to another swf. Can anyone help me plz? It is somewhat
    urgent.
    thanx in advance.

    first of all:
    this is the Flash Media Server and your problem is not
    related to FMS....
    second thing related to the "somewhat urgent" :
    we, users on this forum, are not there to do your job... so
    calm down otherwise no people will answer your question. This forum
    is a free support forum that community of Flash developer use to
    learn tricks and to solve problems.
    Possibles solutions:
    If the two swf are seperate you can use LocalConnection to
    establish a connection between different swf.
    If you load a second swf into the first one you can interact
    like a standard movieClip(only if there from the same domain or if
    you a policy file on the other server)
    You can use SetVariable(via Javascript) to modify a root
    variable on the other swf and check with an _root.onEnterFrame to
    see if the variable had changed in the second swf.
    * MovieClipLoader will do a better job, in your specify case,
    than the loadMovie. Use the onLoadInit event to see when the swf is
    really totaly loaded into the first one otherwise you will have
    timing issues.
    My final answer(lol) is the solution 2 with the
    notice(*)

  • How can i transfer my music from one account to another on a different computer?

    So i have an itunes account on dell laptop and i share that account with other famliy members. I recently bought a mac pro and wanted to create a new account that way i can use icloud, is there any possible way to transfer everything from my old library to my new one or will i lose everything i had on my phone and ipods? Or is it possible to have one account but multiple icloud accounts?

    lisafromwindermere wrote:
    I want to start my own account separate from my parents. Can I transfer my music from one account to another? If so, how?
    Lisa,
    Just get copies of the song files and add them to your iTunes library.  With the exception of any DRM-protected files (purchased before mid-2009 and never upgraded) they will play fine, even though they are technically associated with the original account.

  • How can i move music from one account to another

    I have 4 different accounts in Itunes and i wish to move all the music into one account
    help please !!!!

    You can't transfer content from one account to another account, nor can you merge accounts - content will remain tied to the account that downloaded it

  • How can I transfer sapscript from one client to another

    Please tell me the steps , how can I <b>transfer</b> SAPscript from one client to another (like DEV Client to Test Client)?

    Hi,
    Utilities --> Copy from client.
    If you have to copy from once system to another use Program RSTXSCRP
    Regards,
    Satish
    Message was edited by:
            Satish Panakala

  • How can I transfer mailboxes from one computer to another?

    How can transfer all mailboxes(and their contents from one MBP to another? Migration assistant was no help.

    Select all your mailboxes, and then select
    Mailbox ▹ Export Mailbox...
    from the Mail menu bar. Export the mailboxes to the Desktop folder. Transfer them to the new machine.
    On the new machine, import the mailboxes:
    File ▹ Import Mailbox...

  • How do i transfer music from one account to another?

    I want to transfer music from my account to my friends account, how do i do that?

    You can't transfer content from one account to another.

  • How can i transfer songs from one itunes to another?

    I have a new computer and want to transfer all of my songs from one computer to another.  I have home sharing turned on but can't figure out how to save the songs to the new computer.

    I have home sharing turned on but can't figure out how to save the songs to the new computer.
    First, make sure you've got the home share set up on both computers, as per the following document. If material on the original PC was bought from the iTunes Store, I'd use the AppleID you used for the purchases to set up the Home Share on both PCs.
    iTunes: Setting up Home Sharing on your computer
    Have both computers running and have iTunes open on both computers.
    Now, in the iTunes on the computer you want to transfer music to, select the library that you want to transfer music from, as per the following screenshot:
    Once the other library loads, go down to the bottom of the screen and in "Show:" select "Items not in my library":
    If you want to import all of the songs you can now see, head up to the iTunes menu bar and go "Edit > Select all". Then head down to the bottom of the screen again and click the "Import" button in the bottom-right-hand corner.
    If there's a lot of stuff in your original PC's library, the transfer may take some time.

  • How can I transfer work from one computer to another?

    How can I transfer work from one computer to another?

    Welcome to the forum.
    I can think of three basic ways to accomplish what you wish to do:
    Use the Project Archiver to archive your Project (and check the box to gather the media files), to an external HDD. Probably the easiest way to do it.
    Copy the Project and ALL media files to an external HDD, but be prepared to relink the media files to the Project, as the drive letter (part of the Absolute Path) will have changed.
    Edit loosely, and Share to an AV file, which will be Imported into a New Project on that second computer. Or, edit VERY tightly, and do the same. I like the first, as removing, replacing Transitions, etc., can be much more difficult, unless that "tight edit" is 100% done.
    Good luck,
    Hunt
    Message was edited by: Bill Hunt to correct formatting

  • How can I transfer information from one ipad to another?

    how can I transfer information from one ipad to another ?

    What kind of information? You can sync things like Contacts and Calendars by using iCloud. You can backup one iPad to iTunes on a computer and then sync the backup to the other iPad. You can configure your iTunes content and sync the same content to both iPads.
    It is based on what you want to do. Or are you looking for a way to send files from one iPad to another wirelessly? There are apps to do things like that, as well as cloud services, such as DropBox.

  • How can i transfer apps from one account to another.?

    now i had bought apps with my old account. but when i sync them into my phone i cant update them using my account, i need the old itunes i had. How can i transfer all bought apps onto my new account?

    You can't.
    All 3rd party apps - all paid and free apps include DRM protection which is tied to the iTunes account used to purchase/download the apps. DRM cannot be transferred from one account to another.
    Why did you get a new iTunes account? Changing your email address alone does not require doing so.

  • How can i move settings from one user to another?

    How do I move all settings and permiions from one user to another?

    http://discussions.apple.com/thread.jspa?messageID=11320719&#11320719
    http://discussions.apple.com/thread.jspa?messageID=12317222
    http://discussions.apple.com/thread.jspa?messageID=6331229

Maybe you are looking for

  • I have an HP Pavilion 500-267c, can I install a second hard drive in this PC ?

    My XP tower is no longer working but there is some information on the hard drive that I would like to retrieve, my present PC uses Windows 7 operating system. Can my old hard drive be installed into the new HP without ruining the new computer or the

  • Separate ASM diskgroup for Online redo logs

    Version: 11.2.0.3 Platform : Solaris 10 One of  the Hitachi support guy has suggested to create a separate disk group for Online redo logs. His rationale was that ORLs was write only files and it would be better to put in a separate disk group. What

  • G4 shuts down while working on it.

    hi My G4 mdd lately has been shutting down for no apparent reason. I'll be working on Photoshop, web surfing, etc. and the G4 MDD will just shut off. I read a lot on the MDD having PSU and/or overheating issues. What can I do? Are there fixes for my

  • Podcasts not showing on ipod

    I've just bought an ipod and i am having trouble getting podcats to show up on it. I have been into preferences and made sure that auto update is checked for podcasts and videos bought i can't seem to fing them on the ipod at all. I have checked that

  • Loseing internet connection on large downloads

    Greetings All, I've been trying to do software updates and keep getting this error while downloading large files: "A networking error has occurred: timed out (-1001). Make sure you can connect to the Internet, then try again." As long as the file is