Accessing the main timeline
Hello,
I have multiple instances of a movieclip (a1) within the main timeline. These instances move around via tweening within the main timeline. The instances also appear (are added) and disappear (are removed) while the main timeline is playing.
Within the movieclip is this actionscript:
(code)
addEventListener(Event.ENTER_FRAME, ef);
function ef(evt:Event):void
trace(MovieClip(parent).currentFrame);
(end code)
As soon as an instance disappears... I get this typeError:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at test13_fla::a1_1/ef()
The question then is - How can I access the main timeline from each instance (even when it is not currently on stage)? Is this possible? Any suggestions on how I can keep all of my code within the movieclip?
Thanks in advance!
-Jake
Throughout the timeline the instances are in a motiontween followed by a blank keyframe.
To remove the event listener when it does dissappear I could do a addEventListener(Event.Removed, removeEventListenerFn);.... but I need a way to keep it.
In my real project, each instance draws itself via drawRect and then put into a sprite and added to the main timeline. Then within the event function (where it traces the maintimelines current frame) I need all of the sprites to be removed when the main timeline gets to a certain frame#. I know... confusing...
I just need to find a way to access the main timeline while the instance is removed from the stage.
If, for example, I did this...
(code)
addEventListener(Event.REMOVED, ef);
var ccc:Number = 1;
function ef(evt:Event):void
trace("First Removed: " + MovieClip(root).currentFrame);
addEventListener(Event.ENTER_FRAME, eg);
function eg(evt:Event):void
if(ccc < 10)
trace("I am now removed");
ccc++;
(end code)
... I do not get any errors and I would get this in the output window:
First Removed: 59
I am now removed
I am now removed
I am now removed
I am now removed
I am now removed
I am now removed
I am now removed
I am now removed
I am now removed
Similar Messages
-
Access the main time line function
Hi all,
In as2 we can use _root to access the main timeline function from the inside some movieclip or button.
In as3 how to access the main timeline function from inside the movieclip or button.can any one please tell me."root" is the AS3 equivalent, but using it alone will often not wortk. You more often need to cast it as some form of object before the compiler will recognize it. Using "MovieClip(root)" will usually do the trick.
-
FLV/Mp3 Cue Points for Accessing Frame Labels on the Main Timeline in Flash 8
Hello,
In Flash MX2004, creating cue points for syncing locations on
flv and mp3 files to locations on the main timeline included:
1) Dragging a media component onto the stage
2) Entering file path, frame label name, and time code
information in the component inspector
3) Creating the frame label names on the main timeline, and
4) Enabling the Media Labeled Frame Cue Point Navigation
Behavior
Flash 8 documentation details a considerably different
process of creating cue points. While it discusses how to create
cue points in the flv, I have not been able to locate how to enable
linking locations in flv and mp3 files with frame labels on the man
timeline. It appears that there would need to be ActionScript
necessary to accomplish this that is not available in the docs.
Please advise what ActionScript/process would enable this
function.
Thank you!
James
[email protected]I usually start off solving problems with the livedocs, as I
recommend for anyone. The following link will take you to the
NetStream.onCuePoint handler. This is what you need.
http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context= LiveDocs_Parts&file=00002561.html
You can have this code on the main timeline. When the
cuepoint is hit, it will invoke this event handler and inside is
where your gotoAndPlay( ) should go.
Your other question about the text will get activated by the
same handler. Just have a conditional statement (if, switch, etc.)
to differentiate between the two events. The text itself can be
mask inside a movieclip.
Does this help? -
How do I recerence Movie Clips on the Main Timeline from inside a class?
Hey everyone, this might be a stupid question but I thought
I'd ask cause it's making me nuts. I'm all of 2 days into AS3
(coming from not using Flash at all in YEARS) so feel free to
consider me ignorant. I do have plenty of application development
experience in other areas though.
I can't seem to create a class that can reference an instance
of a movie clip on my main timeline. I'd post code of what I've
tried but I've gone through so many desperate edits & wild
guesses that it was just garbled junk before I deleted it all.
Basically here's how I figured Flash could work, though maybe
it doesn't work this way at all.
I'm assuming that with AS 3 being so big on being a true
object oriented environment, I wouldn't need to mix my code and
interface together. Preferably I'd be using the Flash authoring
tools just to design my interface. Create a button... place it
somewhere... give it an instance name. Roughly the equivilant of
Apple's InterfaceBuilder for those of you that might be familiar
with Cocoa development. I can see maybe having to put a few lines
of ActionScript onto frame 1 (though really I'm hoping Flash would
have a better method of kicking off the application at this point
that using code tied to frames) to load my classes & such, but
after that I'd like all of my code to be held in external class
files.
So maybe I've got:
Interface.fla - My interface
Button_1
Button_2
TextField_1
Main.as - My main controller class using to handle all of my
applications behavior
SomeClass.as - Some helper Class
SomeOtherClass.as - Some helper Class
Main.as would have instructions in its initialization method
to go ahead & attach events to buttons & initialize
anything else that needs to happen when the application starts.
From there on it would all be objects communicating back &
forth. Button_1 would get clicked with would fire
Main.someMethod(). Main.someMethod() would then do it's thing and
set the value of TextField_1. All very clean & code is very
separated from interface.
Unfortunately I can't for the life of me figure out how AS3
classes reference each other like that. There doesn't seem to be
any kind of a global 'root' or '_root' I can use to locate any
movie clips on the stage. I've searched the help & the web for
any kind of simple tutorial but to no avail. My job has tasked me
with building a flash app for a project but I'd really rather not
have a tone of ActionScript just shoved into frame 1. That just
seems... ugh! (::shudder::)
Can someone maybe point me in the right direction here? I'm
really willing to do my homework but I can't seem to locate the
info I need to get started. Also, is there an ActionScript IRC
channel or something maybe?
Thanks,
CliffI worked with the problem last night and the solution I
started coming to involved creating my own custom document class
based off which extends MovieClip. My thought is that way I have
access to the initialization routine of the timeline itself and
that all of the elements on the main timeline should be
"properties" of my custom class.
Is this correct? Is there a down side to doing this & if
so what is it & why?
Also, just for my reference, the last time I did anything
with ActionScript I think I was using '_root' to target the main
timeline. WHat are the global variable names in AS 3? Is it just
'root' & 'stage' or 'Root' & 'Stage' or what? -
How do I set a variable on the main timeline from within a symbol?
Just getting started with Animate and coming to it from Flash, as may be apparent from my question. How do you set a variable to the main timeline from within a symbol?
I have 24 pairs of clickable elements, each in their own symbols, and all 24 of those symbols sit inside another symbol. I want all 24 to be able to set the same global variable when clicked. I can't find that this question is addressed anywhere, which makes me think I may be stuck in a Flash mindset and approaching the task in the wrong way. (There are however MANY discussions of how to address objects at different levels in the hierarchy. That's well covered.)
Relatedly, how do you access a function on the main timeline from within a symbol?
Adobe should consider putting together a support page (or pages) just for folks migrating form Flash. In the materials I've encountered so far there seems to be a studied effort to refrain from mentioning Flash in any way. I imagine there are a lot of people out there like me who have a deep background in Flash coding, but are just getting started with Animate. We don't need help with most of the basic concepts, but we may still have some pretty basic questions about how to accomplish some things in Animate because our Flash knowledge is getting in the way.Hi Bill,
There are plenty of threads on here about scope, but here's one way to create a global variable:
// code on Stage.compositionReady
sym.myGlobalVar = 1;
Then, anywhere in your project, you can check/set that var like so:
sym.getComposition().getStage().myGlobalVar = 2;
And here's one way to create a global function:
// code on Stage.compositionReady
sym.myGlobalFunction = function(){
console.log('myGlobalFunction');
Then, anywhere in your project, you can call that function like so:
sym.getComposition().getStage().myGlobalFunction(); -
Controlling a Movie Clip on the Main Timeline from a loaded SWF?
Is it possible to control a MovieClip on the main timelne from another loaded clip?
I see posts that control loaded clips, but most are all from the loader in the main timeline. I have a moviclip on the main timeline that I want to make visible or invisible depending on what keyframe is playing in another loaded swf.
If I try to call the movieClip from the loaded SWF I get "error #1119. Access of possibly undefined property...." because it doesn't exist in the loaded SWF, just the main timeline.
The old AS2 way just used "_root". Since "_root" doesn't exist any more, how do you control items on the main TimeLine from a loaded SWF?I am not clear what you mean because you are saying you are trying to target a movieclip that does not exist where you are trying to target it.
Try using a trace to see what you are targeting when you you target the MovieClip(parent.parent)....
trace(MovieClip(parent.parent));
The other approach I mentioned earlier is the more OOP-correct approach if you would rather try that way. Here's a rough outline of it...
AS3 - Dispatch Event
http://forums.adobe.com/thread/470135?tstart=120
Example:
Add something to trigger the event in the child (your loaded swf):
dispatchEvent(new Event("eventTriggered")); (
if dispatchEvent problem, see: http://www.kirupa.com/forum/showthread.php?p=1899603#post1899603)
In your loading/parent swf, listen for the complete event on the Loader.contentLoaderInfo. In the complete event handler, add a listener for the event on the loaded swf.
// event handler triggered when external swf is loaded
function loaderCompleteHandler(event:Event) {
MovieClip(event.currentTarget.content).addEventListener("eventTriggered", eventHandler);
function eventHandler(event:Event):void {
trace("event dispatched in loaded swf");
// this is where your main file can set the visible property of your movieclip -
How can I reference the main timeline on a swf once it was loaded into another?
I have an swf with some custon animation functions using actionscript 3. I'm refering to the main timeline with Movieclip(root) and it works just fine.
However, this swf is going to be loaded inside another (a custom player), and when that happends, everything stops working.
I think it's because the Movieclip(root) is now referencing to the loader swf and not the loaded anymore, but I just can't find any information on how to fix that.This is basically what I´m doing here:
I'm placing this code on frame 1, and calling the function textAnimate() whenever I need to insert some text.
// This is a variable I created for tracking the timeline
var base:MovieClip = MovieClip(root);
function textAnimate(movieName:String, espera:Number):void {
//var espera:Number = 1; //Waiting time
var objeto:MovieClip = base[movieName]; //Variable to select the object
var posFinal:Number = objeto.x; // Object position
var posEnter:String = "-160"; // Animation start (relative)
var posExit:String = "+160"; // Animation end (relative)
// enter animation
TweenMax.from(objeto, 1, {x:posEnter, alpha:0, blurFilter:{blurX:40}, ease:Back.easeOut});
//call exitAnimation() after X seconds
TweenMax.delayedCall(espera,exitAnimation);
//exit animation
function exitAnimation() {
TweenMax.to(objeto, 1, {x:posExit, alpha:0, blurFilter:{blurX:40}, ease:Back.easeIn});
The swf works fine, but once it´s loaded into the player, nothing works anymore. Unfortunately, I don't have the code for the player, and can't change anything about it... :/ -
I am making a website based in flash actionscript 3.0 i have a button nested in its own movie clip, because I have the button expanding to be able to read it i have figured out the only way to do this is by creating it as a movie clipa nd inside the movie clip creating it as a button
I added an event listener to the blog button by saying,
blog.addEventListener(MouseEvent.ROLL_OVER,gotoblog);
function gotoblog(evtobj:MouseEvent){
gotoAndStop(2)
this part of the code works it goes to the 2nd frame of the timeline it is in and stops wich is a blown up version of the origanal symbol
i added on frame 2 a second command
blog.addEventListener(MouseEvent.CLICK.gotoblogpage);
function gotoblogpage(evtobj:MouseEvent){
gotoAndStop("blogframe")
trace("the blog button was clicked")
i have named the symbol blog and have name the frame of where the blog page is going to be "blogframe" this line of code at the bottom is where i run into trouble the output window in Flash is saying "The blog button was clicked" just like i want it to. no errors are accouring why than is the playhead not going to frame "blogframe"? if the button is working when i click it the code is right i belive the problem here is it does not want the playhead to go to the frame i want it to. So i gues my question is, how can i make a button withing a movie clip interact with the main timeline?I have a similar problem if could please help me i'd really apreciate it!!
So i have a looping animation of some thumbnails, the hierarchy goes like this
Scene1(main timeline) -> imgBar(MC)->imgBarB(MC within the imgBar MC)
My buttons symbols are in the last MC "imgBarB" where i have this code:
ss1.addEventListener(MouseEvent.CLICK, OneButtonClicked);
function OneButtonClicked(event:MouseEvent):void{
MovieClip(root).gotoAndStop("ssbox1");
I want to control the Btns in my "imgBarB" MC to play a labeled frame(named "ssbox1") on another MC on the main timeline,this other MC goes like this:
Scene1(main timeline)->ssbox_mc(MC where my labeled frame is) -
How to call a function in a class from the main timeline?
Hey Guys
I have a project in Flash with four external AS files, which are linked to items in the library using AS linkage.
What I want to do is call a function in one of these files from the main timeline, how would I go about doing this? I'm not currently using a document class, most of the code is in Frame 1 of the main timeline.
Thanks// change type to the class name from the instance
ClassNameHere(this.getChildByName('instance_name')).SomeFunction(); -
How to control the main timeline from within a symbol?
I have a small world map as a symbol called "verden" and I want the user to click Europe, Asia, or Africa and jump to named labels in the main timeline.
http://www.dagbladet.no/grafikk/neshorn/neshorn.html
On the main timeline a have the label "intro" with a Stop action and the label "europa". At label "europa" I have a symbol also called "europa" which has a display of None at label "intro" and On at the label "europa".
The animation never goes to label "europa"
I have this code on europa in the symbol "verden" :
// insert code for mouse click here
sym.getComposition().getStage().getSymbol("europa").play("europa");
The files are on Dropbox here
Update, now it works:
sym.getComposition().getStage().play("europa");Hi Bill,
There are plenty of threads on here about scope, but here's one way to create a global variable:
// code on Stage.compositionReady
sym.myGlobalVar = 1;
Then, anywhere in your project, you can check/set that var like so:
sym.getComposition().getStage().myGlobalVar = 2;
And here's one way to create a global function:
// code on Stage.compositionReady
sym.myGlobalFunction = function(){
console.log('myGlobalFunction');
Then, anywhere in your project, you can call that function like so:
sym.getComposition().getStage().myGlobalFunction(); -
Moving to a frame in Movieclip timeline from the main timeline
I am in the learning process. Working with FlashCS5 and AS3.
Please bear with me if the issue appears to be too simple for you. Placed a movieclip(mcassessJohn) on the main timeline and moved to the frame labelled "johnFeedback" in the movieclip timeline using the following actionscript code.
mcassessJohn.addEventListener(MouseEvent.CLICK, onJohnClick);
function onJohnClick(evt:MouseEvent):void {
mcassessJohn.gotoAndPlay("johnFeedback");
This works fine. However problem starts when I place a button "questionJohn" in the movieclip(mcassessJohn) time line at frame "johnFeedback" and try to move to another frame by clicking the button and using the following actionscript code;
questionJohn.addEventListener(MouseEventClick,onClick);
function onClick(evt:MouseEvent):void {
gotoAnd Play("johnFeedback");
Placed the above code in actions layer in the movieclip timeline at frame "johnFeedback". I had placed the button also in the movieclip timeline at Frame "johnFeedback in layer buttons. No compiler error.No runtime error. Just nothing happens when I click on the button "questionJohn".
Would appreciate if you can let me know where I am going wrong.Thats because if u assign the listeners to a parent movieclip it will not pickup listener assigned to its child.
A work around is put a invisible btn inside mcassessJohn movieclip on frame 1 and assign onJohnClick function to that.
And one more thing, i think u r trying to perform same operation on both the btns
http://www.darshanrane.com -
Passing a variable from a movie clip to the main timeline
Hi,
I'm having trouble passing a variable from a movie clip in my
flash file to the main timeline.
I have a movieclip with the instance name IntroNav which
contains several buttons. Clicking a button sets the variable
"page" to a specific name, i.e. page = "home"
However, outside of the movie clip, on the main timeline I am
unable to call this variable, and "page" seems to have no value.
Can anyone tell me why this is and how to solve it?
ThanksUmm, yes ... declare your variables correctly.
var page:String = new String(); //proper complete
var page:String; //strict typing
var page:String = "home"; //stirct typing with value
declaration
Do not declare the variable in your buttons, you would have
to do so in every button and be constantly resetting the value.
Declare it on the main timeline at the lowest level. You do not
need to use it as a _global, you just need to resolve your path
issues. You can 'set' the variable value from a button, without any
problem, but you have to call to the variable correctly.
You do not 'name' a variable as "_root.page" , the '_root'
refers to the lowest level of the SWF or the main timeline, as does
a call to ' _level0' (that's a zero). If the variable is declared
on the main timeline, and you're calling from the MC/button or
anywhere you can refer to the variable by calling to it by
the proper path of '_root.page'
To set the variable from any of your button/MC instances
call:
_root.page = "value"; OR _level0.page = "value";
But you must have the varibale declared on the main timeline,
and only once and the playhead should be stopped or it will reset
the value to the default upon looping. -
How to remove a function on the main timeline within a movie clip
How do you remove a function that is coded on a frame in the main timeline from within a movie clip? I tried this, but no dice:
infoGraphicDisparity.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene);
function fl_ClickToGoToScene(event:MouseEvent):void
parent.removeEventListener (Event.ENTER_FRAME, parent["enterFrameHandler"]);
MovieClip(this.root).gotoAndPlay("disparity");
this is the event I am trying to remove:
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
any help would be appreciated as always.
Thanks!from any frame (that executes after enterFrameHandler is defined) in any display object in the display list
stage.removeEventListener(Event.ENTER_FRAME, MovieClip(root).enterFrameHandler); -
Play a movieclip once, then go to the next frame on the main timeline
Hello, I'm sorry for the long topic's title.
I have an animation I'd like to use as an INTRO in my flash
movie. I will joint it inside a movieclip, giving it the istance
name "INTRO". And I position it in the first frame of the main
timeline.
How can I make possible that played once my intro (my
movieclip) the player jumps to the second frame of the timeline,
named by the istance "HOME".
Is it possible?
Thankyou very much for your help,
and great things.
Stebianchion intro's first frame place:
if(!this.played){
_level0.gotoAndStop(2);
and on its last frame place:
this.stop();
this.played=true;
_level0.gotoAndStop(2);
// or this.removeMovieClip(), if this is no longer ever used.
and if you use this, you don't need the frame 1 code. -
Using Flach CS4 and action script 2.0 how do I advance to a specific frame of the main timeline when a movie clip instance come to the end of its timeline?
code on the last frame of your movieclip instance:
_root.gotoAndStop('whatever_frame'); // will work unless this swf is loaded into another swf. in that situation, you should use a relative path to the main timeline (eg, _parent or _parent._parent etc).
Maybe you are looking for
-
ABAP Service Users not working - important
Hi, I installed finally BPC 75 NW, and I cannto get ito the application for the 1° time because I have several issues.... I get the error "The user ID, password cannot be authenticated. Make sure you entered valid credentials". On Server Mgr. i get
-
G4 iBook works in Safe Mode, but not in regular mode (stuck on blue screen)
14" iBook G4 1.2GHz with 1 gig of RAM. I recently had an issue with this machine in that the image on the screen would freeze but the cursor would be able to move around. This was narrowed down to an issue with the logic board. I wanted something a l
-
Tab key won't work. Works in IE8 and Safari but not Firefox. Thoughts?
About a week ago, the tab key stopped working in Firefox (when I updated Firefox?). It works fine in IE8 and Safari. I love Firefox but will have to switch if I can't get this resolved. Thanks.
-
Do I need continuous internet connection to use cc
I frequently do not have an internet connection. Can I still use Photoshop and Lightroom when disconnected?
-
How exporting music or other media list from iTunes from computer works?
Hi, I want to know how exporting music or other media list from iTunes to computer works, because I have exported the songs list of Music from iTunes to computer in a text file, but I have no idea how it works.