ActionScript 3.0 :: Accessing Main Stage Variable From Within MC
Apr 7, 2011From within a movie clip, I'm trying to update variables on my main timeline. I tried both _parent.variablename and _root.variablename, but neither worked.
View 4 RepliesFrom within a movie clip, I'm trying to update variables on my main timeline. I tried both _parent.variablename and _root.variablename, but neither worked.
View 4 RepliesI have a class, the relevant parts of which are defined as follows:
class myClass extends MovieClip {
public function myfunc() {
trace( "mainVar: " + _root.mainVar );
}
}
As you can see, I want to access the variable "mainVar", which exists in the main movie, from within the class. This works fine, if I have only one instance of the class. But, if I have more than one instance, within separate movie clips, the value of mainVar is always taken from the first instance. How do I refer to the actual instance from within the class?
Here's my main class:
Code:
package
{
import flash.external.ExternalInterface;
[Code]....
Basically the class waits for the callback variable (my_msg). The problem is: I need to set the dynamic textbox text to my_msg variable.
How can I access it? I know I can access a public var in the timeline with functioname.variable but I can't define a public var inside a function, right?
I'm was getting good with as2 but recently made the mind switch from, I'll learn as3 tomorrow to as3 is awesome. The problem for me is that I don't understand the scope for classes. I know I can trace a variable on the main time line when the var is declared in the class. But how do you access a main time line var from a class? Here's an example - main time line Monkey.fla
Code:
var cagedMonkies:int = 10;
var monkeyTransport:MovieClip = new CarTrunk();
[Code]....
Here's my main class:
[code]...
in the timeline I have a dynamic text box named my_textbox: var my_test:main = new main(); my_test.check_DVBViewer(); my_textbox.text = ??Basically the class waits for the callback variable (my_msg). The problem is: I need to set the dynamic textbox text to my_msg variable. How can I access it? I know I can access a public var in the timeline with functioname.variable but I can't define a public var inside a function, right?
I wanted to remove an event listener from main class stage, but i get the error 1120: Access of undefined property stage. How do I actually access the stage?
custom class:
import main;
main.disableVcam();
main class:
public static function disableVcam():void {
trace("disable");
stage.removeEventListener(MouseEvent.MOUSE_MOVE, movevC);
}
my movie is linked to an external class called game, and in the game cosntructor I am trying to access instances on my stage. I have tried MovieClip(root).instancename, root.instancename and even tried adding an event listener to listen when the movie is done loading because I thought maybe it was because the instances on the stage weren't created before the constructor is ran. This is the main class, shouldn't it be easy?
View 2 RepliesI've made it this way1. I made clip and it's main class (eg. timeline.as) - at this point it works2. I put code from main class to another class (eg. timeline_template.as) and in main class (timeline.as) I inherit it by :public dynamic class timeline extends timeline_template {3. I added stage items declarations in timeline_template.as because without that any code couldn't reach target an I got 1120: Access of undefined property xxx after these steps whole clip works but items on stage ( buttons, etc. ) are not affected by code. That's logical because code references to properties declared in timeline_template but not in timeline.fla. But how to get around that - I need several usage of timeline_template and I would like to avoid code redundancy
View 3 RepliesIf I wanna to access a variables which located on frame 1 of the main stage, can I write a script to access that in a movieclip which located in frame 2?
Or the movieclip has to be in frame 1 to access that variable using parent method?
On my movie clip timeline, what's the syntax to access a variable on a main stage timeline?
View 1 RepliesHow can I pass a variable defined on the main stage to a onClipEvent handler?[code]
View 1 RepliesI have a movieClip named MC, and it's enabled with action script, with the class name MC_Rectangle and a Stage.I override the MC_Rectangle class file in a mc_rectangle.as external file.here is the code:
package{
import flash.display.*;
import flash.events.*;[ code].....
I have new a object in the main stage var
mc_rect:MC_Rectangle = new MC_Rectangle()
in main stage:
1. how can i access the variable "sequence" in "mc_rect"
2. how can i pass parametre from main stage to mc_rect via function setSequence(data:int)?
3. how can i call the function in addSequence() in mc_rect.
in asp.net, i usually use mc_rect.sequenct,mc_rect.setSequence(data), mc_rect.addSequence() to achieve my goals......btw, can function in mc_rect return out result to main stage?
I'm trying to catch a variable content (set on the main timeline) from a movie clip added to the stage. I need to set a condition with that variable, so here's my line :
Code: Select allif (MovieClip(root).screenMode == ("full"))
But it's not working, I'm also trying to trace the variable with that command :
Code: Select alltrace(MovieClip(root)[screenMode]);
But this doesn't work too.
- I have A.fla.
- A.fla includes buttons, movie clips and also B.swf is loaded in A.fla using a LOADER
- i want to access elements in A.fla, from the actionscript codes inside B.fla to modify those movie clips and buttons based on actions going on in B.swf
for instance, lets say there is a button X in A.fla, and there is a button Y in B.fla, B.swf is loaded into A.fla, and I want the button Y to erase button X when clicked.
general question: accessing elements in a stage, through a SWF file loaded into that stage.
I have 2 movie clips, one being loaded into a container MC via "loadMovie();"In the main movie there is a variable with no value, in the external movie there are 5 frames, each with a value to update the variable in the main movie.
IE: if on frame 1, global value = 1 / if on frame 2, global value = 2 / etc etc I'm familiar with passing variables INTO an external swf, but am stumped on how to do it the reverse way.
I'm using flash CS 5.5 and AS 3.0 . I've a movieclip that contains 3 more moviclips that are acting as toggle buttons. I want to change frame number / label of main time line upon click of these buttons. With _root no longer available I dont know know how to do it.
View 2 RepliesI 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].....
How can I access the main timeline from each instance (even when it is not currently on stage)? how I can keep all of my code within the movieclip?
How can I call a MC from a class other than my main. I am making a side scroller and I when the player hits certain parts of the level I want the floor to fall out from under him (think Mario). I created a new class to attach to the different MC of the floor but I cant figure out how to access the player MC from the class. The MC name is playerMC that was exported for actionscript, and the instance name is player_mc. This is the class.
[Code]....
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
[code].....
I'm definitely more designer than flash developer (as most of you might know. At least those that hang in the lounge or Arena). I need to know how to allow a loaded .swf file to control the main timeline in AS3.
I have a container .swf that includes global controls (jump menu/volume control) and branding. Loading a swf for the dialogue boxes (timeline animated ... although I realize there may be better ways to handle it). Another swf for a simcity-ish illustration that has animated elements with various states. I need all to be able to communicate with each other. I was able to load the movies no problem. Even communicate with the loaded ones from the main timeline. Just need to be able to go the other way.
I have a question about accessing functions or variables on the main timeline from a loaded swf. I know that there are a few ways to do this
1. Casting the timeline as a movie clip
Loader SWF Script
var testText:String = "Test";
var myLoader:Loader = new Loader();
loadData("loaded.swf");
function LoadData(aURL){
myLoader.load(new URLRequest(aURL));
addChild(myLoader);
}
2. Cast the timeline as a generic object
var parentObj:Object = this.parent as Object;
parentObj.unloadSWF("loaded.swf")
Why can you not just reference the main timeline of the container swf directly.
Let us say we have a movieclip "mc1" on the stage. We also have another movieclip "mc2" inside mc1. We have declared a variable, say, var number1:Number=5 on the first frame of the main timeline. Now we go inside mc1 and then inside mc2 and write some code on its first frame. Is there any way to use the variable number1 over here? Can properties of mc1 be altered using the code written here? In AS2, it could be done using the "_parent" command, but it doesn't seem to work in AS3. (when we use parent and try accessing a property, it says that it is possibly undefined)
View 3 Replies1. I made a variable in main.swf, var num:Number = 5, and then i load home.swf, how do i access the var num from home.swf ? In AS2 i can use trace(_root.num), how do i do this in AS3?
2. How do i access a movie clip from different loaded SWF file?
I was trying to access some nested movieClips from the main time line but it was giving an error. What I have is a movieClip on the stage called "dog" and inside this movieClip I have two nested movieClips called "dogLH" and "dogRH". The movieClip "dog" was brought to the stage using actionscript 3.0 and when I tried to move the moveClips inside "dog" it gave me an error.
This is the code I have:
var dogog = new Dog();
dog.x =200;
dog.y =150;
[Code]....
What is strange is that if I add the movieClip "dog" to the stage manually and try the same thing it works. Any idea why it doesn't work when it is brought to stage with actionscript, but it works if I bring this manually?
import com.hydrotik.queueloader.*;
.................
public class Main extends MovieClip
{
[code].....
I need to get access to loaded STRATTransitions.swf from the main movie and remove some text from it. There is no source code available for the swf.
I have a MovieClip, that I'm going to add to the display list with my document class at runtime beacuase there will be many instances of it. The MoviClip "box" has 3 more MovieClip instances inside it,and each of those three have two more.It looks like this:
box
circle 0
oval0
oval1
[code]....
I've beein digging forums everywhere but cant find the solution to my problem...
I have an external swf "advert_3.swf" loading into the main index.swf.
advert_3.swf has two buttons: one needs to go to "services" frame the other to "events" within a content_mc which is in the index.swf.
that is in the index.swf:
ActionScript Code:
var request:URLRequest = new URLRequest("advert_3.swf");
var loader:Loader = new Loader();
loader.x = 35;
[Code].....
I have a function on the main timeline named startClips. Now, I want to call this from within two movie clips, the other nested inside the other. In other words, I have a movie clip called holder, and inside of a holder, I have a movieclip called homebase. Now, here is all the code I've been trying to use to access the startClips function which is own the main timeline from the movieclip homebase:
MovieClip(root).startClips();
MovieClip(root.root).startClips();
MovieClip(parent.parent).startClips();
this.parent.parent.startClips();
I need to be able to call a method from a component located under the main application in Flex 4. Can anyone tell me please how to do this without using FlexGlobals please?[code]
View 3 RepliesI have a movie clip menu on a main timeline and inside that movie clip I have created four buttons dynamically. How to access those nested buttons/movieClips (add event listeners etc) from main timeline? Here I am adding menu to the display list on main timeline:
[Code]...