ActionScript 3.0 :: Calling A Variable (tween) From Another Frame?
Jul 29, 2009
This is my first time working with flash and actionscript. when my project increased in size, it became frustrating to look through 2 or 3 hundred lines of code to find my mistakes. I decided to code in frames, so that one animation or movieclip could be handled by each frame, making it easy to edit each individually. So far so good, but i am trying to reuse a tween from an earlier frame, and it doesn't seem to work. I was under the impression that if you define a variable in a previous frame, you can use it in a later frame.
here's what it looks like
(frame 5)
var closeMenu:Tween = new Tween(mainMenu_mc, "x", Strong.easeOut, 238, 900, 3, true);
there is a frame in between that does: gotoAndStop(20);I want the animation to start right when it gets to frame 20:
(frame 20)
closeMenu.start();
TypeError: Error #1009: Cannot access a property or method of a null object reference.
I can copy and paste the original var and change the name from closeMenu to, say, closeMenu2 and it will work fine, but I feel like what I did should work.
View 0 Replies
Similar Posts:
Jun 11, 2009
i am making a simple slideshow in AS2 (Flash CS3). I got all the core logic working fine in a FLA frame action - now trying to externalize it into a class. The first snag I hit was in trying to setTimeout -- when I passed a class method as the setTimeout function, it no longer could talk to the class variables/methods. I fixed this by passing along an instance of the class to the class method called by setTimeout something like this:
setTimeout(myMethod,delay,classInstance);
Now I've got a similar problem with my Tween.onMotionFinished() handler -- i want it to call another method in my class but it doesn't know what the class is or how to access it.How should this be accomplished? I've tried a similar trick in which I try to stash a class instance inside the tween (through bracket syntax eg. myTween["classInstance"] = this; but this doesn't seem to work.
Is this a case where I basicallyneed to create an event listener in my class & then just send an event out when the tween finishes? Or is there a simpler way to let the tween know about the class (without relying on instance names of the class itself)?I'm still new to OOP so not completely got my head around what can/can't access my class methods/variables especially when I'm creating objects like Tweens inside my class.
here's my current SlideShow.as class:
Code:
/*
imports
*/
import mx.transitions.Tween;
import mx.transitions.easing.*;
[code]...
and then I just create a slideshow from an existing framesequence MC (who has stop() on frame 1) in the FLA thusly:
Code:
import com.pixelfarminteractive.slides.SlideShow;
//SlideShow(slideMC:MovieClip,easeTimeSec:Number,holdTimeSec:Number,numSlides:Number)
var ss = new SlideShow(slideshow_mc,2,2,4);
ss.start();
View 17 Replies
Aug 5, 2010
My problem is my redrawMenu() function is not being called when onMotionFinished() is called.
[Code]...
View 1 Replies
Dec 4, 2009
My question has to do with tweened buttons that call an element onto the stage from right , on centre stage this called element stops centered. This is as far as I get...What I would like to happen is ,on the press of another tweened button the element from first tweened button vacates left and is replaced with called element from this button, and so on for 5 separate buttons, of course these can be pressed in any order..
View 5 Replies
May 11, 2011
I am a first time flash-maker, and I sure how to get things to work as planned.I have written the following code:
stop();import flash.events.MouseEvent;Weightlifting_btn.addEventListener(MouseEvent.CLICK, CursorClick);function CursorClick(event:MouseEvent):void{gotoAndStop("25");}
But my problem is that i have a motion tween that startes at frame 5 and ends at frame 25. And the code says that at will go to and stop at frame 25.what I really want it to do, is to go to frame 5, play the motion, and stop at frame 25.
View 2 Replies
Nov 19, 2010
I have an problem whereby I have created a Frame by Frame dancing human figure and now I want to move it across the screen as well as scale it using a Tween.
I have spent quite some time slightly adjusting the upper arms, forearms, hands, legs etc and creating a new keyframe for each movement. All the movements are all in one layer... ie the forearm doesn't have it's own layer etc. I am running the animation at 24fps so there is quite bit going on.
I now realise that I should have created a symbol/movie clip from the first image I created and then scaled and moved the image first before animating it's limbs but I only realized that after hours of work and I would hate to start all over again.
So basically what I have is a dancing human figure in the one spot moving it's arms and legs and I want it to move across the screen and become larger by scaling it using a Tween. I could of course re-edit each keyframe by slightly scaling and the slightly moving the figure but that will take quite some time to get right as there will be a fair bit of trial and error doing it that way.
View 3 Replies
Feb 2, 2010
I have function on my main timeline, triggered by a tween event. I need to call this function WITH the triggering tween event from inside a movieclip. Is this possible and if yes, how do I do this?
ActionScript Code:
TriggerTween.addEventListener(TweenEvent.MOTION_FINISH, function)
Is my code on the main timeline. TriggerTween is a simple Y-tween that triggers an alpha tween inside my target movieclip. I need to have the option to trigger the alpha tween with the Y tween from inside my target movieclip.
View 0 Replies
Jul 20, 2010
I've created a multi frame MC for placing each of my slide out images on and have added a tween slide out MC.my onrelease is working and I've correctly switched the image frame for the relevant picture being clicked before playing the tween MC.However once the MC stops playing the image MC is reverting back to showing frame one image.Why is this happening? Also why when the slide out MC is over the smaller clicklable image the hit area is still available through the image being shown?I've ensured that the slide out MC is on the top most layer, how do I make its backgroud solid so any clickable item underneath is not available.
View 7 Replies
Sep 14, 2009
In the old motion model it was as easy as highlighting all of the frames, converting them to keyframes then removing the tween. But I have no clue how to do it with the new motion model.
View 6 Replies
Aug 13, 2011
I have a button in "frame 1" that leads to "frame 2". The file has simple code:
myButton.addEventListener(MouseEvent.CLICK, gotoFrame02);
function gotoFrame02(event:MouseEvent):void {
gotoAndStop(2);
}
The problem is no transition when the frame changes. Is it possible to apply Tween transition when the frame changes?
View 2 Replies
May 29, 2011
The website is build from a main swf file. "main.swf" which is basically the backround with menu and the first thing that opens in index.html. Then there is a second flash. called login.swf which is loaded onto the main flash.The second flash is loaded using next code:
Code:
cont._lockroot = true;
cont.loadMovie("login.swf");
[code].....
View 5 Replies
Sep 26, 2009
I have a button that uses the Load Graphic Behavior for bringing a SWF, but i want the SWF to come in a specific frame instead than starting at frame 1. For examplel; i click the button, the behavior of Load Graphic brings my SWF to stage but i want to start at frame 50, not at frame 1. How can i do that?After i use the Load Graphic Behavior i try using a gotostop frame, but doesn't work.
View 13 Replies
May 20, 2010
i got an AS3 3d gallery that calls external swf animations...
However these animations loop...and on the last frame i need the gallery to appear again.. Is there a way (either AS2 or AS3) to put a code on the main timeline at the last frame that calls my swf gallery back? It doesn't have to load inside the swf...it just needs to appear as soon as the other one ends..
View 2 Replies
May 2, 2009
What happens if I have a previously allocated variable (new), then I set such variable to null in order to mark it for GC but then a few seconds later I call new again on it (not knowing if it has been GCed), and the GC still has not cleaned the memory address containing the variable.Would the first (new) allocation be garbage collected
View 5 Replies
Dec 6, 2011
I have a function that has a For Loop inside it. Inside that For Loop I am defining a button and calling to another function if clicked. The issue is (since I shouldn't put functions inside other functions) how do I get the variable being processed in the For Loop to be considered in the function that was just activated by pressing the button.
Here's the code. All variable are defined elsewhere in the code.
function populateBox(DataInput:XML) {
linkAmount = DataInput.country[boxPartNum - 1].link.length();
/// defines amount of links being made
for (k=0; k<linkAmount; k++) {
myLink = new LinkClass();
[Code] .....
I need to trace the "K" used in the For Loop.
View 3 Replies
Mar 16, 2012
Basically I'm creating a question with 4 answers (i.e. a,b,c,d).I have my question working fine, but I'm having a problem adding a check mark beside the answers once the user clicks the submit button.I've created four instances of my check mark; rightAns1_mc, rightAns2_mc, rightAns3_mc, rightAns4_mc. I've set them all to _invisible = false; I've also set up a variable; nCheck:Number = 0; and when the user clicks one the radial buttons I have the variable change (i.e. if they click A, it set to nCheck = 1; if they click B, it sets to nCheck = 2; etc)So in my if statement for the submit button I figured I could have rightAns(nCheck)_mc._visible = true;
View 1 Replies
Nov 29, 2011
var myvar = "this is the value of myvar";
var notMyvar = "this is some other variable";
var thirdVar = "this is some third var";
var nameOfVarToCall = "myvar";
//print the content of the var name specified, in this case "myvar"
I have a string which contains the name of a variable I need. What I want to do is find out the name of var (in this case "myvar") and use the name to access the value of the var (in this case just print out the value). Is this feature available in Actionscript. I know it's available in PHP and can come in very handy.
View 2 Replies
Sep 14, 2011
i have the following script, i'm just doing tests over failed attempts, I have a "cnc+i" dynamic variable, wich is a BitmapData type, i'm sure it's declared since the trace function returns true at the output, what i have a problem with, is at the moment of attaching the Bitmap, i don't know how to call it, and i don't want to do it manually like this: cnc1. Since i am planing on putting the attachBitmap inside a for loop:
ActionScript Code:
import flash.display.BitmapData;
this.createEmptyMovieClip("CNC",this.getNextHighestDepth());
CNC._x=50;
[Code].....
View 1 Replies
Dec 20, 2009
A very simple question. Can two tween events be called one after the other using the same variable name? (so that they occur simultaneously, no callbacks or anything like that).
Code:
var outTween:Tween;
outTween = new Tween(big_play_btn,"alpha",None.easeNone,1,0,1,true);
[code]....
View 6 Replies
May 14, 2009
I've been reading over numerous tutorials and guides as well as the Language Reference for ActionScript 3.0 but cannot quite seem to find anything to learn what I need (which I guess is because everything I have read assumes you would already know how to do this sort of thing).On my stage I have one button (mybtn) and one MovieClip. Within the MovieClip I have numerous other MovieClips (the different parts of a character, leg, arm, head, etc).
One of those MovieClips, lets call it "upper_left_arm" (within the other MovieClip "character") is comprised of two Keyframes, frame 1 and frame 2. There is also a second layer with AS in it, which just has "stop()" in it so it doesn't endlessly play.When I click the button on my stage I want to change the playhead to frame 2 and then stop within the "upper_left_arm" MovieClip.I gather that I almost certainly need to use gotoAndStop.However, most information I have found concerning buttons, AS3 and the gotoAndStop command relate to "scenes" which as far as I can tell are nothing to do with what I want.
Code:
stop();mybtn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
upper_left_arm.gotoAndStop(2);
}
The "(2)" is the part I think I have horribly wrong, I've tried various other things after "upper_left_arm.gotoAndStop" with no success. In fact, the MovieClip "upper_left_arm" now loops round merrily despite the "stop()" in the AS in that MovieClip itself .
View 2 Replies
May 27, 2009
i have created array of button and i want to call a frame according to the order or number of that button when it is clicked.
like
if i click 1st button it call a frame 1 of symbol named A
if i click 2nd button it call a frame 2 of symbol named A
if i click 3st button it call a frame 3 of symbol named A
[code]....
View 2 Replies
Jan 27, 2011
Beginner question here. Basically I have the following code:
if (_root.obj1 == 1) {
n = _root.invArray.length;
_root.obje1._y = _root.inve(n)._y;
[code].....
View 1 Replies
May 27, 2011
I'm trying to get to grips with having a function that can accept an input that is passed to it as it is called, and then use that input in its workings.As I'm writing more code, it's becoming clear that this is something that I need to pick up, but despite reading and playing about with it, I'm still a little confused.The code is designed for a character's "level up" screen. When the button next to a stat is pressed, I want it to pass the name of that stat to the statUp function, which will increase the selected stat by one.In my main file I have this code, to call the function when the button is pressed. (In this example, it is the Strength button)
ActionScript Code:
_root.buttonStr.onPress = function()
{
[code]........
View 6 Replies
Feb 16, 2005
say I want to declare a global variable in my main movie on a mouse event (button) and give it a value "functionA".
then I want to load an external .swf into a clip (with the same mouse event)
then I want some code in the loaded .swf to execute a function of the same name "functionA"
how would I code this?
this way I could load the same .swf but execute different functions depending on which button triggered the load... comprende?
View 5 Replies
Oct 18, 2011
I'm having a problem where I have a button on the main timeline that when clicked needs to gotoAndStop first on frame 3, where there is a movieclip, that i want it to gotoAndStop on frame 30 (of that movieclip). Any ideas?
I can't have it just gotoAndStop on frame 3 and then have the code to gotoAndStop on frame 30 either because I need to be able to have the moviecliped called like this a number of different times.
View 2 Replies
Feb 16, 2009
I am designing a surf board website and I am trying to get the boards to display properly in a scrollerI have everything in place except I need to call a frame name from the XML. in the instructions for the horizontal scroller it says I needed to uncomment a piece and comment another piece but i can't get it to work..I need it the timeline to go to the frame labeled "go"
View 1 Replies
Jan 25, 2011
I have a simple problem. I'm trying to call a function from a frame in an animation.
Code:
function goBack(evt:Event):void {
gotoAndPlay(this.currentFrame - 100);
}
This code lives in frame 1 of my movie. On frame 143 I have this chunk of code.
[Code]...
View 2 Replies
Nov 14, 2011
I am trying to trace a variable string from inside a movieclip which is inside another movieclip on the main timeline using:
[Code]...
View 6 Replies
Apr 8, 2006
I have a photo gallery for a painter rotating through images via XML. She wants a little sold sign to appear on ones that have been sold. I'd like to figure out a way to make it appear/disappear with a _visible = true/false statement that I can call from via the XML file.
Something like:
<node>
<img>"img.jpg"</img>
<sold>true</sold>
</node><node>
<img>"img2.jpg"</img>
<sold>false</sold>
</node>
Is this possible? I know that may not be a correct syntax, I can't get it to work.
View 3 Replies
Jan 30, 2009
How do I pass a variable to function when calling it with interval.
This:
Code:
doFlip(1);
to something like this:
Code:
myInterval = setInterval(doFlip(1),2000);
View 2 Replies