Jump to content
Search Community

Can't get tweens to work???

azpaul test
Moderator Tag

Recommended Posts

Hello,

 

I have been trying to tweek some code I just wrote and fix a looping problem that popped up. So, going back to basics I have dissected each portion of code and seeing if I can make it more simple and efficient. I have had some breakthroughs. However, while working with the simplified code, I am having some problems with the tweening. Maybe I am doing something wrong or forgot something important to make them function.

 

The fla and code is very small and I hope by walking through I explain it thoroughly.

 

I have my main fla with 2 actionscript files.

My main fla includes these two .as files. This is it for any scripting in my fla file.

 

action.as simply pulls data from an xml file and populates an array. I am trying to learn how to make this data available to other functions without creating a special class. I think I have been successful by declaring the variables at the top of the script. I can seem to use them in any function that way regardless of the file.

 

So now that I have my data I call a function that turns 8 symbols off dynamically. I was not able to do this before and it removes a whole lot of code. I will eventually be implementing this to turn 80 symbols off all at once. The function is called byteMe as is the actionscript file.

 

So far so good. Right after I turn the symbols off, I use timlineMax to turn 1 symbol on. I can't get any of the Tweens to work. Now with my previous experience with declaring the variable in the first .as file, I figured I could do this as well and use tl.timeline.append anywhere in any AS file. Not so, for some reason I have to have the var statement in the function of the tweens? Should not work this way and it does not on my original project, for the most part. So, am I doing something wrong here?

 

I have uploaded the fla file and the two .as files. I'm baffled. I have been working with code non stop now for three weeks and I thought I was starting to get the hang of things and now I can't seem to figure this one out?

 

Also, if I put the tweens in the fla file with the var statement within the timeline statement , it works. I can access the object's visible property directly using object.visible = true.

 

Please let me know if you have any question.

 

Thanks.

Link to comment
Share on other sites

Hello,

 

Of course I can not just let a problem lie without trying to figure it out. I have been able to get the tweens working again in the .as files. In order to do so I have to still declare a new variable in the function of the tween. This still doesn't seem right.

 

A question with alpha. In the bytMe.as file I pretty much set all the symbols.visible to false. In the timer.as file I try and set the alpha to one of the symbols so it fades in. I can use autoAlpha but it pops in like a visible:true. In order to get the alpha to fade in to 1 I have to set the symbol in the bytme.as function to alpha=0. When you call an alpha:1 and the object is set to visible=false, shouldn't the alpha automatically set it to true and the fade in?

 

Isn't it more efficient to turn the visibility of the object off when not showing on the stage and not just setting the alpha to 0?

 

Thanks..

Link to comment
Share on other sites

There are a few problems and misunderstandings I see:

 

1) You set up your FLA so that there are two frames - the first one has a keyframe with your various number MovieClips and the next frame has another keyframe that's completely blank. Flash always plays through your MovieClip's timeline and when it reaches the end, it loops back to the beginning and plays again unless you stop() it. So Flash is bouncing back and forth between those frames over and over and over. Consequently, your ActionScript is getting executed each time it loops (12 times per second in your case). The tween never gets a chance to begin because it keeps getting overwritten by a new one. Why do you have the extra blank keyframe? Why not just delete that completely?

 

2) You can certainly create a TimelineMax outside your functions and it will persist. However, keep in mind that by default, TimelineMax instances will play immediately. So if you append() a 1-second tween immediately and then 5 second later append() another 1-second tween, the first one will play fine but the second one won't unless you restart() the tween or gotoAndPlay(1) because your 2nd tween's start time will be at exactly the 1-second mark but since you're at 5-seconds, it's already AFTER the tween would have completed. Think of it like a linear timeline where you're currently looking at the 5-second spot but your tween resides back at the 1-second spot. If you haven't watched the basics video on TimelineLite/Max, please do so at http://www.greensock.com/timeline-basics/

 

3) The "visible" and "alpha" properties are completely different in ActionScript. When you set visible to false, it does NOT make the alpha 0. It sounds like you were expecting TweenMax to automatically force alpha to 0 initially if visible was false and you did an alpha tween. Not so (and it shouldn't). You should set your alpha to 0 first if you want to fade the object in to 1. Feel free to use the TweenMax.fromTo() method if you want to set the start and end values for your tween.

 

By the way, I'm not sure what your final goal is, but you may not even need to use TimelineMax if you're just wanting to execute individual tweens and don't need advanced control over sequencing or controlling groups of tweens as a whole. You can use TweenMax independently of TimelineMax, just so you know.

 

Hope that helps.

Link to comment
Share on other sites

Hi Jack,

 

As usual, you have cleared some issues up. This is for that project that we discussed earlier. I thought I had it completed but ran into some looping issues. So out of frustration I basically started from scratch creating a single fla of each stage to get a clean working segment. That is where I ran into these quirk, or shall I say my misunderstandings. To answer your questions below.

 

1) You set up your FLA so that there are two frames - the first one has a keyframe with your various number MovieClips and the next frame has another keyframe that's completely blank. Flash always plays through your MovieClip's timeline and when it reaches the end, it loops back to the beginning and plays again unless you stop() it. So Flash is bouncing back and forth between those frames over and over and over. Consequently, your ActionScript is getting executed each time it loops (12 times per second in your case). The tween never gets a chance to begin because it keeps getting overwritten by a new one. Why do you have the extra blank keyframe? Why not just delete that completely?

 

Based on a previous discussion, I converted the first frame to a blank key frame. I guess it produced a second frame which I saw but did not think was an issue. I think at one point I actually saw that happening. The whole movie was kind of stuck and flickering. By breaking down the segments the way I did, I found a quirk in the timer function and this may be the culprit. It basically skips the counting every other time when my xml dtata loder is not commented out?? Will look deeper into that.

 

2) You can certainly create a TimelineMax outside your functions and it will persist. However, keep in mind that by default, TimelineMax instances will play immediately. So if you append() a 1-second tween immediately and then 5 second later append() another 1-second tween, the first one will play fine but the second one won't unless you restart() the tween or gotoAndPlay(1) because your 2nd tween's start time will be at exactly the 1-second mark but since you're at 5-seconds, it's already AFTER the tween would have completed. Think of it like a linear timeline where you're currently looking at the 5-second spot but your tween resides back at the 1-second spot. If you haven't watched the basics video on TimelineLite/Max, please do so at http://www.greensock.com/timeline-basics/

Nice to know... Thanks. I did watch that video and that is what got me up and running before. So if I understand right, I have a declaration of tl for a new timeline. Where ever I put the tl.append timeline it will always look at starting at frame1. But if I declare say 3 variables for 3 different timelines, they will run separately in the functions that I declared them in, but at frame 1 respectively?

 

3) The "visible" and "alpha" properties are completely different in ActionScript. When you set visible to false, it does NOT make the alpha 0. It sounds like you were expecting TweenMax to automatically force alpha to 0 initially if visible was false and you did an alpha tween. Not so (and it shouldn't). You should set your alpha to 0 first if you want to fade the object in to 1. Feel free to use the TweenMax.fromTo() method if you want to set the start and end values for your tween.

I knew that the were different. I did not realize that in order to fade in, the property must be set to alpha:0 first. That explains why it behaved the way it did. I saw that alpha had to be 0 before I could fade it to 1 but did not know why.

 

By the way, I'm not sure what your final goal is, but you may not even need to use TimelineMax if you're just wanting to execute individual tweens and don't need advanced control over sequencing or controlling groups of tweens as a whole. You can use TweenMax independently of TimelineMax, just so you know.

TimelineMax allows me to easily set the delays and tweens when I want them, alteast where I think I want them. I have experimented with tweenMax alone as well.

 

As usual, thanks for the suggestions and it did help! You explain things so us novices understand.

Link to comment
Share on other sites

Timer issues. OK, Nailed it but I do not understand why.

var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();

I originally had this out of the function that I call to get the new data. When I moved it into the function, it no longer interferes with the timing? Would you know why a declaration like this would interfere with another function? I have the whole zip file on actionscripts.org. This was caught by luck...

Link to comment
Share on other sites

Removing the second key frame did not fix that issue with the timer function. Other than trace statements, I am not sure how to trace this problem to it's roots.

Any suggestions?

 

Without seeing your file, I'm not sure what to tell you. Unfortunately I don't have a lot of time to dedicate to general consulting on other people's files apart from helping with GreenSock-specific questions. I'd highly recommend trying to isolate the issue by building a separate, bare-bones FLA file that only incorporates the absolute essential part that deals with your timer. Slowly build on until you hit the problem. This is one of the most effective ways to troubleshoot an issue that has you stumped.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...