AS3 Many tweening problems - actionscript-3

I am having huge problems with AS3 and the tweening class. It just stops for no apparent reason...
My code is a menu of side panels that slide in-and-out when the user clicks the tabs.
It looks as follows:
var mainContent1X:Tween = new Tween(MainContent1, "x", Strong.easeOut, MainContent1.x, 325, 1, true);
var MainContent2X:Tween = new Tween(MainContent2, "x", Strong.easeOut, MainContent2.x, 1750, 1, true);
var mainContent3X:Tween = new Tween(MainContent3, "x", Strong.easeOut, MainContent3.x, 1750, 1, true);
var MainContent4X:Tween = new Tween(MainContent4, "x", Strong.easeOut, MainContent4.x, 1750, 1, true);
var mainContent5X:Tween = new Tween(MainContent5, "x", Strong.easeOut, MainContent5.x, 1750, 1, true);
var MainContent6X:Tween = new Tween(MainContent6, "x", Strong.easeOut, MainContent6.x, 1750, 1, true);
It just stops for no reason at all like the code isn't being executed. Sometimes only one tween happens and the others don't. Sometimes it works the way I want it to!!! I can't figure out why this is happening, I am relatively new to AS3, I'll appreciate any help.
Regards
Luben

I assume its a lifetime problem of your variables. If your tween variables are only in local scope of a function, at the end of that function they are lost and so your Tweens.
Make them class variables or even better, use Tweener.

Thanks Daniel,
I declared the variables outside the function and all is fine. It seems that the garbage collector was clearing them at the wrong time. The code looks as follows now:
var mainContent1X:Tween;
function name() {
mainContent1X = new Tween(MainContent1, "x", Strong.easeOut, MainContent1.x, 325, 1, true);
...
}
I'll look into Tweener/TweenMax although I'm hesitant about using 3rd party software.
Thanks again,
Luben

Related

Actionscript code not executing but no compiler errors

Below is the code I did for a basic button and menu interaction using flash tween and ease class for animation. Tested movie but no response and no compiler errors either except output panel says :
TypeError: Error #1123: Filter operator not supported on type builtin.as$0.MethodClosure.
at CloudRail_fla::LaunchDeckcontrols_3/frame1()
where Cloudrail is my document name.
Here is the code :
switchbd_btn.addEventListener.(MouseEvent.MOUSE_DOWN, ShowswitchBD);
var switchbdIN:Tween = new Tween (switchbd, "x", Strong.easeOut, 1089.05, 277.85, 1, true);
var switchbdOUT:Tween = new Tween (switchbd, "x", Strong.easeOut, 277.85, 1089.05, 1, true);
function ShowswitchBD(e:MouseEvent):void {
if (switchbd.currentFrame == 1)
{
gotoAndStop(2);
switchbdIN.start();
}
else {
gotoAndStop(1);
switchbdOUT.start();
}
}`
please what could be wrong?
switchbd_btn.addEventListener.(MouseEvent.MOUSE_DOWN, ShowswitchBD);
should be
switchbd_btn.addEventListener(MouseEvent.MOUSE_DOWN, ShowswitchBD);

Start Tween when other Tween reaches certain position AS3

I'm trying to create a simple slideshow of 3 images going from left to right.
I want to check if the last image is on stage ( so the image3.x = 0 ) in order to start the new Tween.
I thought it would be something a simple as the following code, but that doesn't seem to work.
function Start() {
if(image3.x == 0){
var myTween:Tween = new Tween(image, "x", None.easeNone, -140, 640, 10, true);
}
}
stage.addEventListener(Event.ENTER_FRAME, Start);
Split the original Tween in two parts, from -140 to 0 and from 0 to 640.
var tween:Tween = new Tween(image, "x", None.easeNone, -140, 0, 10, true);
Wait for it to finish:
tween.addEventListener(TweenEvent.MOTION_FINISH, onZeroReached);
Then do the second part plus whatever else you want to do:
function onZeroReached(te:TweenEvent):void
{
tween = new Tween(image, "x", None.easeNone, 0, 640, 10, true);
// do additional stuff here
}
code untested

what is wrong with this method of animating a jpg background that dynamically changes with buttons

OK here what I'm envisioning and keep in mind ive only just started playing with flash so I really am a total novice at this point:
I want to have two buttons which load different jpegs which are pretty large (about 5000 width x 600 height) to animate as the page background. so in my BG layer for the main timeline i added a container movie clip (5000x600 also) and in the container movie clip's timeline i have it classic tweening across the stage back and forth. then on the main timeline i have my two buttons which are supposed to load the backgrounds. the thing that seems to be messing it all up is the fact that i call "stop();" in my action script to stop on my 3rd frame of the main timeline after the preloader etc. in my testing i added yet another movie clip that animates and it keeps animating when i cal stop(); but the background image is not animating any more.
sorry for my lack of understand and THANK YOU for your patience ;)
anyways here is the main action script code:
import fl.transitions.*;
import fl.transitions.easing.*;
// tween the main menu into place upon opening
//var moveTween:Tween = new Tween(mainmenu_mc, "y", Elastic.easeOut, mainmenu_mc.y, 70, 2, true);
// claim MCs from library to use on stage when needed using addChild
var bg1:blueBG = new blueBG();
var bg2:greenBG = new greenBG();
var bg3:testBG = new testBG();
//var p4:page4 = new page4;
containerBG_mc.addChild(bg3);
var pageMoveTween:Tween = new Tween(containerBG_mc, "alpha", Strong.easeOut, 1, 0, 1, true);
blueBtn_btn.addEventListener(MouseEvent.CLICK, btn1Click);
crazyBtn_btn.addEventListener(MouseEvent.CLICK, btn2Click);
function btn1Click (event:MouseEvent):void {
var btn1Outro:Tween = new Tween(containerBG_mc, "alpha", Strong.easeOut, 1, 0, 1, true);
btn1Outro.addEventListener(TweenEvent.MOTION_FINISH, runBtn1Transition);
function runBtn1Transition (event:TweenEvent):void {
containerBG_mc.removeChildAt(1);
containerBG_mc.addChild(bg1);
var btn1Intro:Tween = new Tween(containerBG_mc, "alpha", Strong.easeOut, 0, 1, 1, true);
}
}
function btn2Click (event:MouseEvent):void {
var btn2Outro:Tween = new Tween(containerBG_mc, "alpha", Strong.easeOut, 1, 0, 1, true);
btn2Outro.addEventListener(TweenEvent.MOTION_FINISH, runBtn2Transition);
function runBtn2Transition (event:TweenEvent):void {
containerBG_mc.removeChildAt(1);
containerBG_mc.addChild(bg2);
var btn2Intro:Tween = new Tween(containerBG_mc, "alpha", Strong.easeOut, 0, 1, 1, true);
}
}
and of course there is a stop(); action on the 3rd frame of the main timeline in a different action script layer
SUMMARY:
3 layers:
AS3 layer
button layer
BG layer
duties:
AS3 layer just has a stop action on frame 3
button layer contains two buttons to dynamically change the background jpeg image. the action script for this layer is what i posted above
BG layer has the containerBG_mc movie clip instance which on its own timeline animates left and right
if you need further clarification let me know
You're tweening something with the timeline in the container movieclip, so you're not tweening the container itself. Than you're adding movieclips to the container, so they are not affected by the tween.
What you want to do is add the backgrounds to the movieclip you're tweening in the container like this:
containerBG_mc.tweened_mc.addChild( bg3 );
You can set the name to tweened_mc in the properties-panel when selecting that tweened object.

Flash Action Script 3 rotate button

Could anyone tell me whats wrong with this code? I'm attempting to rotate a button in action script 3 and i keep getting the error:
ArgumentError: Error #2025: The supplied DisplayObject must be a child
of the caller. at flash.display::DisplayObjectContainer/removeChild()
at
distributor_app_fla::MainTimeline/NewChartOptionsReturn()[distributor_app_fla.MainTimeline::frame1:218]
at
distributor_app_fla::MainTimeline/ClickNewChartOptions()[distributor_app_fla.MainTimeline::frame1:101]
I've already Googled the error and everything i read told me to remove the child then re-add it to the frame but it continues to break at the same spot.
code:
//defined
var btnNewChartOptions:NewChartOptions = new NewChartOptions();
btnNewChartOptions.y = 279;
btnNewChartOptions.x = 439;
//created
function NewChartDown():String
{
btnNewChartOptions.addEventListener(MouseEvent.CLICK, ClickNewChartOptions);
btnNewChartOptions.alpha = 0;
addChild(btnNewChartOptions);
var NewChartOptionsTween:Tween = new Tween(btnNewChartOptions, "alpha", Strong.easeOut, 0, 1, 1, true);
return "NewChartSelected";
}
//actual code on button
function NewChartOptionsDown():String
{
rightGrayOut.alpha = 0;
addChild(rightGrayOut);
var grayOutTween:Tween = new Tween(rightGrayOut, "alpha", Strong.easeOut, 0, 1, 1, true);
var rotateTween:Tween = new Tween(btnNewChartOptions, "rotation", Strong.easeOut, 0, 180, 1, true);
return "NewChartOptions";
}
any help is appreciated!
There will be no need to remove and re-add the object because it is either present and available to the method or not, meaning if it were available to the method for removal then it would also be available for addressing and manipulation. This sounds a whole lot like a scope/visibility issue.
This code is on frame 1 on the timeline, which means that it should be able to address anything that's directly on the stage or assigned to a variable that is in the same scope at the time the function is run. (In the _root scope if this was AS2, like the methods on frame 1)
Is btnNewChartOptions inside another DisplayObject, like a sprite you use to hold all your buttons or something, as opposed to sitting directly on the stage? Maybe you can describe the object heirarchy you are trying to address as well as how the button gets attached to the stage (e.g. instantiated and attached at runtime or placed on the stage in a keyframe).
Can you provide the error that was being thrown before the add and remove fix was attempted?
If looks like to me the object has not been added yet to the display list.
// replace the following lines
removeChild(btnNewChartOptions);
addChild(btnNewChartOptions);
// with
if( !this.contains( btnNewChartOptions ) ){
return "";
}
[EDIT]
Your code.
//var created
var btnNewChartOptions:NewChartOptions = new NewChartOptions();
btnNewChartOptions.y = 279;
btnNewChartOptions.x = 439;
//button code clicked that creates button
function NewChartDown():String {
btnNewChartOptions.addEventListener(MouseEvent.CLICK, ClickNewChartOptions);
btnNewChartOptions.alpha = 0;
addChild(btnNewChartOptions);
var NewChartOptionsTween:Tween = new Tween(btnNewChartOptions, "alpha", Strong.easeOut, 0, 1, 1, true);
return "NewChartSelected";
}
//function for button
function NewChartOptionsDown():String {
rightGrayOut.alpha = 0;
addChild(rightGrayOut);
var grayOutTween:Tween = new Tween(rightGrayOut, "alpha", Strong.easeOut, 0, 1, 1, true);
var rotateTween:Tween = new Tween(btnNewChartOptions, "rotation", Strong.easeOut, 0, 180, 1, true);
return "NewChartOptions";
}
In your code you provided you are only doing addChild(btnNewChartOptions); in the NewChartDown function.
So that tells me that NewChartOptionsDown can not be called until NewChartDown has been called first. Because the btnNewChartOptions has never been added.
What you can do is move addChild(btnNewChartOptions); outside of the function.
//var created
var btnNewChartOptions:NewChartOptions = new NewChartOptions();
btnNewChartOptions.y = 279;
btnNewChartOptions.x = 439;
addChild(btnNewChartOptions);

ActionScript Bitmap Filter Tweening

i can't seem to tween any bitmap filters. here's my code:
var dropShadow:DropShadowFilter = new DropShadowFilter();
mySprite.filters = [dropShadow];
var dropShadowTween:Tween = new Tween(dropShadow, "distance", Regular.easeOut, 4.0, 20, 2, true);
what is my mistake? i've also tried the following but it doesn't work:
var dropShadowTween:Tween = new Tween(mySprite.filters[0], "distance", Regular.easeOut, 4.0, 20, 2, true);
the main problem with the tweening of filters is that you have to reassign them before they change, just changing the value of the dropshadow wont make a difference until you call mySprite.filters = new Array(dropshadow) again. Just incase it becomes needed further down the line!
i would personally use TweenLite by Greensock with its FilterPlugins, works a treat!