ActionScript 2.0 :: Controlling MC Bahaviour Using Global Variables
Nov 13, 2009
I want to replicate the movement of the movie found on [URL] (under collections) where once u press the collection name, movie gradually loads, then if u press another button the movie on stage first unloads and than new movie appears and gradually loads and so on.
I have tried to solve this problem using variable, to tell the movie on stage what to do.....But
I have a problem controlling my MC using _global variable.
I'll try to explain:
I have created empty MC where I attach movie from my library using buttons.
Works fine.
I'm working on a flash project consisting of 25 separate .swf file. each file has a audio narrative in it which is controlled by "play", "stop" button.the way my project works now is every time you unload a current .swf and load a new one, you have to press "play" to turn on the audio narrative. since there are 25 narratives in total, you can see how annoying having to press "play" every time you load a new movie would get.
what I am trying to do is add a global audio control in first "index" movie which would allow a user to globally turn the audio narrative "on" or "off".so for example, if they like to hear the narrative, they can turn audio on and have the audio start automatically each time a new .swf loads. if they choose to turn the audio "off", then the audio should not come on automatically.as a added twist to this, I would like to give my user an additional control over the audio by allowing them to use the "play", "stop" buttons within each of the .swf files.
I realize that the issue of global variables has been discussed several times on this forum in the past. I have carefully read each one but I could not find any clear, definitive answers. Let me first give the basic idea of what I plan to do with Flash.
I will be simulating electrical, pneumatic, etc diagrams. I will, for an example, have a circuit breaker that can be clicked, thus changing its state from open to closed. Once this is changed, the flow from that circuit breaker will also be changed. This could all be accomplished inside of this file fairly easily, but this Flash file will be linked to hundreds of other flash files, each containing a unique drawing, but the variable for that circuit breaker, and all the other conditions need to be passed from drawing to drawing.
I have spent a lot of time researching online and browsing this forum, but I cannot find a solution to this problem.
In as2, we had global variables which were accessible from anywhere within the movie. How can i achieve similar functionality in as3? You see, in my site, after a user logs in, there are several pages, and each of them calls a php script, and i need to pass the user id as a parameter to them! So as soon as the user logs in, I need to store his id in some place, which i can read from any class or subclass within the whole movie! Can you please tell me how to do this? oh and yea, i am new to as3, so please try to be as descriptive as possible!
Problem: global variables disappear.I am using CS4 but still coding in AS2. I am on a Mac, latest OS.I loaded and then trace my _global variables for three screens and they follow me fine until,.... then on the the screen i have tiny bit of code:[code]Could it be the level 99 I use. I tried using 0 and it did not work?
Where do I place a function, at the lowest level, so I can call it from any other container above it? For example, I have 3 frames and they all need to use the same function, called "myFunction()". Do I really have to create it in each frame? There has so be a lowe level where this can be placed? Is there a good simple description of AS3 Hierarchy somewhere? Also, how do you specify global variables in AS3?
I've done a search and all I could find are creating global variables through Classes.
Is there a way of creating them on the timeline? I have a preloader.swf that loads another swf to itself and would like to read the values off of the parent.
I'm trying to create a global variable that initially stores a 0.Then via a function will change the value of that global variable, and allow the other functions to access the new number. I have it working where it adds 1 to the variable, and stores the number 1 however, I cannot get the number to add up beyond 1.I have this in my first layer,frame.
_global.thisSound = 0; function PlaySound(){ temp = _global.thisSound;
it has many different sections(15 or so). Now i have made the movie and created all the checkboxes needed in the form.
I have given each one an instance name - e.g. chk_individualtax1
Made a global variable for each checkbox to get the .selected value - e.g. _global.individualtax1 = chk_individualtax1.selected;
At the end of the movie I have put a trace command to check that the variables are working( because they are on different timeline levels)- e.g. trace(individualtax1);
Now my problem comes here because now I am trying to send these variables off to the server using the getURL command. - e.g. getURL("send.php", "_blank", "POST");
This works and the email is sent off to me via php. however only the variables on the main timeline are sent? is there a difference in fetching global variables off different levels of the timeline Now should I rather be using the loadVariables command and if so how?
I'm trying to make my FlashVars global so that they can be accessed in all of my scripts. I have an external .as file called 'globalvars.as' and it has the following code:
Code: package{ import flash.display.*; public class globalvars extends MovieClip{
[Code].....
But I get the following error: Error #1009: Cannot access a property or method of a null object reference. The Flashvars are set right as I can access the variables in the main timeline, just not the external .as file. I'd like these variables to be accessible to other external .as files which is why I'm doing this.
I have MC timelines, with script and variables inside them, and i need to access these variables in the main timeline, or from other MC timelines, how do you do this. I guess i baisically need to store the variables somewhere they are globally accessable, but i don't know how?
are variables global through scenes? I am working on a game show w/multiple scenes and i need a variable that i used in a previous one, but i dont know if it carries through.
In AS3 I want to use Global variables (not many) that can be accessed in any class and declared somewhere where the fla file or any as file can use them and be ale to change the value of them anywhere. Can I do this in AS3?
I have a movie clip of an explosion which is done in code because I am randomizing the direction and amount of debris from the explosion, so it's a movie clip with one frame, and all animation is done in code. Problem is, I'm trying to pause the game from the main timeline when the player presses "p". Right now I have it so it turns the variable gamePaused = true and calls the function pauseGame() which stops everything else. However I don't know how to access the variable gamePaused from inside the explosion movie clip's code. If I can somehow check that variable in the movie clip, I can pause that animation until the player presses "p" again.
So basically, how do I access a variable in the main timeline from a movie clip?
Also just to point out, all of these explosions were created as Sprites in the main timeline's code, any solutions I have found online didn't like that. So just keep that in mind.
Here's the main timeline code:
//This Creates An Explosion<br> function createExplosion(explosionX, explosionY, explosionSize):void{<br> //This Creates The Explosion Movie Clip var explosionSprite:Sprite = new Sprite;
I have a function in which I declare a bunch of variables that I need to be globally accessible from outside the function.[code]I need numVals to be accessible from outside the function.I tried changing the name to _global.numVals and it didn't work
I have defined Variables at the start of my script, with _root, to make them valid globally.
Then, in several functions and IF loops, I change the values of these variables, again referencing them with _root.
Then at the end of my script, I want to collect these global variables and send them to a PHP file to late store them in a db.
The problem is that at the end of my script, the variables do not contain any data, I used trace() to test this.
They only seem to contain values inside the IF loops which would mean they are behaving as local variables only?
I also tried replacing _root with _global but got the same results.
I have over 1000 lines of code at the moment so I will only post a snippet here of the general method I used, perhaps some experienced users will spot what I am doing wrong[code]...
I have a project that needs some global variables. While developing on my local machine I made a 'globals.as' file which contains the following: ActionScript Code: package { public class globals { public static var gData:Object = {}; }}
I import that using ActionScript Code: import globals; Then in my code if I need to create or access a global variable I can do something like: ActionScript Code: globals.gData.myNewVariable = "whatever";
This all worked fine until I exported the project to the web, suddenly it's as if globals.gData is not an object anymore. Only thing I can think of is that it's not importing globals.as. Is there a special way I have to embed globals.as into my project?
Code: onClipEvent(load){ _global.tinta=0xFF0000; tintb=0xFF0000; box = new Color("_root.boxy"); //This instance is named "boxy" } onClipEvent(enterFrame) { box.setRGB(tintb); //Turns it red } This works and makes the box red. However, if I change it so it's "box.setRGB(_global.tinta)", it turns it black. Even setting "tintb=_global.tinta" and using the "box.setRGB(tintb)" doesn't work any more. Why doesn't setRGB() like _global variables?
how a can i declare global variables in mx 2004? i want 2 declare a variable that can be accessed by all buttons & movie clips. i tried to put it in the main thingie (the one u find in the actions panel when you're not selecting anything)
I have some problems with my homepage. I want the user to be able to chose their own language. Sedish English or german. What I want is that you klick a flag in the intro of the page and then Flash should remember that and get my variable datas in the right languages. As I said, three flags. what should i wright on them? actionscript? ex:
i am wondering where and how i can insert global variables in my code (below)....or is that too 'C' a concept!?!...see what i am trying to do here is this...onClipEvent calls within it attachMovie from my library with the appropriate linkages...a few setProperty here and there...what i want is a few characters initialised above the rest of the code...why?...coz as u will see, when k=0, a movie is picked up, put at level m=1...
...the second time round the loop begins, k=1 so a movie gets picked up again at random...now this is where i need ur help...the second (and subsequent 3 movies) need to be placed on top of the basemovie...i am trying swapdepths here...good hoice?...anything else i can do?...yet to figure out reducing the opacity of subsequent movies...see i am looking for a motion trail kinda effect...so at one point of time 5 mc will be visible...total no. of mc=250 and at random they get picked up over and over again...
I'm working on a Flash game (AS3) and have come to a point where I need to change the value of a global boolean variable from within a movieclip. After searching all over I have yet to find a solution. Essentially, the problem is that I have a movieclip that contains a section of animation for my game. When this movieclip is told to begin its animation, it checks these global variables to see which of six animations to play. When it finishes any of these animations, I need to set the associated variable and increase the score.
and does not write "false" back to the global that was defined on the setup script, rather it creates it's own "local" global variable called _global.shorts which is no good to man nor beast!
I have tried using _root._global.shirt, _root.shirt, adding the variables to the loadMovle call, but nothing seems to let me trace the global with the correct value in the shirt popup.
Is there something I need to do to pass the variable to the shirt.swf when I load it?
I don't see it documented anywhere, nor have I heard it mentioned but it appears that Flash has a problem displaying _global variable values in dynamic text boxes when setting the var property in the property inspector. I am not able to display the variable successfully using just the var property, but I can dynamically set it via ActionScript. Seems odd to me that it doesn't work. It works as expected with timeline variables. Also...can someone explain why you DON'T type _global variables? In fact, you'll get errors if you try to initialize a global variable as such:
I'm a student building a flash presentation in Actionscript 2.0 for a company wanting a virtual tour of a building. Each room in the building has clickable objects that need to trigger an action (by going to another slide), which we have happening; however, we don't know any way to code the flash so that it remembers where you have been, what has been clicked, etc. so that by the time you've clicked everything in the building, another slide plays saying "Congratulations!" or something. I've been told that we need to use something called a global variable to implement this function.