Different Take On Global Variables
Good morning,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.Thank you,Corey Willis Info:CS4, AS3, WINXP
Adobe > ActionScript 3
Posted on: 12/05/2008 09:48:46 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
[CS3] Global Function = Global Variables As Well?
CS3/AS2
if i have a global function with some variables defined within it, are the variables global too? if not how would i make them global too?
_global.function someFunction() {
var cake = 10;
var book = 15;
}
someFunction is global so therefore "cake" and "book" are too?
EXTREMELY URGENT - Creating Global Variables Using Names Of Other Variables...
I have variables xtile and y tile within a movie, and I need to create a global variable that will tell all other movies that this particular movie is situated on tile [xtile][ytile], so I need to know how to create the global variable: _root.objectmovie_xpos_xtile_ypos_ytile = true;
I know how to create global variables, and how to have other movies read them, but how do I actually create a VARIABLE with this name? I tried set ("_root.objectmovie_xpos_" + xtile + "_ypos_" + ytile") = true, but that doesn't work (which I kinda knew already but thought I would give it a shot)
any ideas peeps?
please help, its vital to a project I am doing
cheers all
Are Global Variables Really Global?
Hi everyone!
This might sound like a dumb question, but i've just been struggling with variables (more specifically global variables) for the last 3 hours, and now that i made it work, i'm wondering if my solution is the "normal" one.
From what i gather, when you declare a _global variable, you can just use it from any timeline without using a path, right? I have a variable (whichHoliday) which i initiate in the first frame of the main timeline, this way:
_global.whichHoliday="";
I want to give a new value to this variable inside a MC on that timeline. The only way i could do it was by using:
_global.whichHoliday="whatevervalue";
Shouldn't i have been able to use only: whichHoliday="whatevervalue" ?
Why did i need to use _global again to set the value?
Thanks for any input!
[F8] My Global Variables Are Not Global
Hi
I have a problem, my global variables aren't global, as soon as a new timeline is entered the global variable is undefined. (I read somewhere in a forum that it is only possible to use a couple of global variables for F8, could that be correct?)
I use:
if (_global.thing == true){
thing._visible = true;
}
This works for the timeline where true was set and one more timeline, but as soon a third timeline is entered the global value is set to undefined!
What could be the problem?
I am soo grateful for any suggestions!
Thanks!
My Global Variables Don't Seem So Global
what the hell am i doing wrong!?
heres what i've got:
in my UI class i have this:
#include "ContainerClass.as"
#include "MapClass.as"
#include "ObjectiveClass.as"
#include "SponsorClass.as"
#include "MeasureClass.as"
#include "InitiativeClass.as"
#include "AnalystClass.as"
#include "MilestoneClass.as"
#include "StoryLineClass.as"
#include "CommentsClass.as"
var dbPath = "localhost";
_global.scriptPath = "http://"+dbPath+"/strategymap/scripts/";
then in all of the included files i have something like:
myloadvars.sendandload(scriptPath+"/filestoload.whatever",x,"POST");;
sometimes i just want to break something. grrrrr!
Global Variables Within MCs
ive used this code on a button:
selectedscene = "begincontactus";
and at the endd of the current scene ive said:
gotoAndPlay(selectedscene);
this works fine when the button is on the main timeline but when i put it wihtin an mc on the main timeline it doesnt work. do i have to use targets for gloabl variables? how?
Global Variables
ive used this code on a button:
selectedscene = "begincontactus";
and at the endd of the current scene ive said:
gotoAndPlay(selectedscene);
this works fine when the button is on the main timeline but when i put it wihtin an mc on the main timeline it doesnt work. do i have to use targets for gloabl variables? how?
Global Variables
ive used this code on a button:
selectedscene = "begincontactus";
and at the endd of the current scene ive said:
gotoAndPlay(selectedscene);
this works fine when the button is on the main timeline but when i put it wihtin an mc on the main timeline it doesnt work. do i have to use targets for gloabl variables? how?
Global Variables
ive used this code on a button:
_root.selectedscene = "begincontactus";
and at the end of the current scene ive said:
gotoAndPlay(_root.selectedscene);
this works fine when the button is on the main timeline but when i put it witin an mc on the main timeline it doesnt work. do i have to use targets for gloabl variables? how?
actually i have five MCs wtihin an MC on the main timline.
there is a button within each of the five MCs. an action on the buttons changes the variable. so ive created the variable first in the main timeline and refered to it from within the buttons' actionscripts. so i created
_root.selectedscene = "empty"
on the first frame of the movie just to create it.
why isnt it working??????????
Global Variables
hi there,
how can i properly define global variables, meaning variables which can be seen from any scene in my movie?
if i start defining it (like normal) with "var myVar = 42" i can access it only from within this scene. if i just use it without defining it, i can access it from any other scene too, but it doesn't look very clean to me, so is there a better solution for this problem?
bye, stevie.
Global Variables?
Simple, easy question that I can't seem to find the answer to: How do you declare and change a global variable? Thanks
-Llama
Global Variables
I'm trying to do an Audio ONOFF button for my scene. This is what I did:
-Created a movie instance containing the wav file.
-Assigned the above instance to an object with "new Sound" command in first timeline frame:
suono = new Sound(audio); *audio IS THE WAV INSTANCE*
aa=true; *this global variable is intended to be used for the switch behaviour*
-Created a second key frame on time line and placed "Stop()" command.
-Created a switch button.
-Assignet the following script to the button instance:
on (release) {
aa=!aa;
if (aa==false) {
suono.stop();
}
else {suono.start()};
}
When first I press the button, the music stops, but after that I cant let it start again. The global variable "aa" works at the beginning, but seems that it cant keep the "false" value after the mouse leaves the button. This is what I think. Maybe the debugger would give great help in this matter, but I cant see the "aa" variable on it.
Any idea?
Global Variables
Hi,
I have two issues.I would greatly appreciate if someone can help. First thing, How do I create global variables like. I have created some variables by loading a xml file while loading the movie. I want to reuse them in the movie clip mousedown events. Now I am again loading it unnecessarily.
Secondly how do I reuse the functions I created in one movie in another. Now I am needlessly typing the same function in all the MCs.
Please help
Thanks
-r-
Global Variables?
Are there any way of making global variables in Flash 5??
I want to set some variables and access them in a couple of different scenes.
/Micke
Global Variables
Hi
How can i set a global variable at the beginning of a flash movie, so that the values are available to all other frames and MCs within it?
I tried using set variable commands in the first frame, but found that subsequent frames did not retain those values.
Your help appreciated.
BoB.
Global Variables
Maybe this is too much of a VB concept but can I create a Global Variable in flash. By that I mean one that will be recognized in all of the movie clips with out using _root???
Any help would be greatly appricated.
Global Variables
Hello,
i'm trying to construct a menu and need to have global variables that i change when the menu item is loaded
i have a global function for loading animations on scene 1 and before that function i instance the varaibles. in my case the variables are always reloaded with the same value
Where should i instance the variables ?
Thanks
Global Variables?
Hello All!
Ok, I need help with a variable for controlling a button / Movie clip.
Here is the movie I am working on...
http://isaid.com/test/mmibt_main002.html
If you take a look at the movie you will notice that when you roll over the button(s) the doors for the box on the page close and then when you click the button the doors open back up with new content.
With that said here is my problem.
If you roll ever the button but you do not click it and then you roll over the next button the doors close again.
This is what I am trying to stop.
Once the doors are closed I want them to remain closed until you click a button.
This is the script I currently have on the button to open and close the doors.
on (rollOver) {
_root.mainDoors_in.gotoAndPlay(30);
}
on (press) {
_root.mainDoors_in.gotoAndPlay(60);
}
Pretty straight forward.
Now here is what I was playing with to try and set a variable to keep them closed.
on (rollOver) {
set (IsDoorClosed,True);
if (IsDoorClosed==False)
{
_root.mainDoors_in.gotoAndPlay(30);
IsDoorClosed=True;
}
}
on (press) {
if (IsDoorClosed==True)
{
_root.mainDoors_in.gotoAndPlay(120);
IsDoorClosed=False;
}
}
When this is in use the buttons do not function at all.
plus I think this is wrong anyway as I believe it would be a local variable and I think need a global variable.
I have limited knowledge of scripting so I hope I am at least on the right track.
Can anyone help me in this dilemma??
Much thanks!!!!
Rick
Global Variables...
I'm a little confused. I've been reading a lot about global variables in flash. Now, from what I've read, if I define, for example, a variable in the first frame in the first scene of my project, like so test="0"; then I should be able to access it from anywhere in the movie, right?
I've also noticed you don't need to declare a variable type in any way. (Like int test=0; or string test=boohoo Does Flash determine what variable type is desired by the contents of the variable itself?
I know these seem like little kids questions but I really want to get a good understanding of basics in Flash. Im one of those do it yourself-ers so Im teaching myself the language. (Also because I cant afford classes or books, LOL.) This site has indeed been a lifesaver!
If anybody knows any good websites with comprehensive flash basics (Like the question Im asking above.) Id appreciate it. The help files that come with Flash itself arent too comprehensive.
Thanks!
Global Variables...
Could somebody explain how to set/use global variables? I think that would be a great help...thanks a lot....
Oh My, Global Variables
I have Flash 5
I never thought I would be asking this, but, how do I specify a global variable? ! Imagine, me asking this, oh well.
Any help?
Help Using Global Variables
I'm having some trouble with global variables.
I declared it like this in the first frame:
_global.current = "song2";
note: song2 is a movie clip
Then when I have a stop button I call on the variable like this and it doesn't work.
on(release)
{
_root.current.gotoAndStop();
}
Can someone point out my mistake? Thanks.
Global Variables
How do you declare a variable that is useable by everything. In and out of movieclips?
Global Variables Help Plz
I'm trying to make a fade in/out effect with my sections of text after a link if pressed. To do this I have to make flash remember which movie clip is already on the screen. The best way to do this is by using a global variable. Each text field MC sends a variable to let the movie know taht its currently on the screen. When a link is clicked. I try to reference this variable and use it as the MC variable name to tell the text on the screen to fade out and then use an absolute action with no variables to tell the textviewer to fade in the correct text. The text then sends a global variable out again telling flash what clip is on the screen, and the cycle goes on and on. Problem is my variable isn't working. All these textMC's are in the same frame and on different layers of a movie clip. After the links are clicked they all end up on top of each other. This has to be a variable problem because if the variable worked the old clips would fade out and then go to and stop frame 1, which is blank frames. Anyway here is the code and where they exist.
// I declare this in _root on frame 1
_global.current;
//This is the text clip located at _root.sections.wdsection.htmltextmachine.htmltext1
_global.current = "htmltext1";
//Here is the hotspot on(press) code In english it tries to call the global variable and uses its value as the MC instance name. Then it calls upon the the new text Mc to run the fade in animation, which leads to that code above this. This clip is located at _root.sections.wdsection.navhtml I also tried to call it using _root....._global.current.gotoAndPlay.........
on (press) {
_root.sections.wdsection.htmltextmachine.current.g otoAndPlay("fadeout");
_root.sections.wdsection.htmltextmachine.htmltext1 .gotoAndPlay("fadein");
}
The concept is pretty simple but its giving me hours of trouble. Help I'm Dying here!!!
Global Variables
I am loading some variables from external file. Is there a way to make a variable global? so i can accesst is from anywhere in the movie. Thanks
Global Variables
for some reason i can't call my global variable. First i set the global variable:
_global.myVariable = "newGlobal";
how do i call it from anywhere in the movie?
Global Variables?
I dont know if I'm missing something really obvious, it seems that any variable value I set isn't global across different timelines:
//this is in the first frame of the _root timeline
n = 1;
//this is on a button within the _root.movie1 timeline
n = n+1;
but it doesn't change the value "n", unless I put the button on the main timeline.
I've corrected the problem using a function, but I've always thought that variables were "global".
Any thoughts?
Cheers
Rob
Global Variables
k this is whats happening
you press play and it plays to frame 2 and
1) _global.pts = 0;
2) pts = 0; ' pts = dynamic text box, both instance name and var name = pts;
then on frame one a movie clip with no name starts
on frame one it
1) _global.tVal = (pts+50) ' the timer is counting down from 50 to 0 in a graphic way... no variables involved.
when it hits frame 10 (10 fps) it
1) tVal -= 1;
and a layer 2 has a movieclip which does the following
onClipEvent (enterFrame) {
count = 1;
with (_root.bird) {
if (_root.goal.hitTest(_x, getBounds(_root).yMax, true)) {
_Y -= 10;
for (count=_root.pts; count<tVal; count++) {
_root.pts += 1;
}
_root.bird.visible = false;
_root.play();
}
}
}
so its looping until pts = tVal which is the timer value
so like every time the timer drops a second tVal -= 1; so they are the same. then if _root.bird hits _root.goal it counts until it hits fifty... since i hit frame 10 tVal should = 49 but when i test it it ALWAYS equalls the number i added to pts when i formed tVal
tVal = (pts + X) X being the number that is ALWAYS displayed
i want the numbe displayed to be X to be the time displayed....
i cant post the fla so try and help with this...
- Goat
Global Variables
Hi there
I have a frame in my movie with two MC's, one Mc loads some ASP variables and put them in a for loop..no prob.
rigth next to it is another MC that needs to use the same variables but in a different kind of loop...now for the prob.
when I play my movie the first MC gets the variables fine and does what it is supposed to do but the second one does nothing...is there some reason I shouldnt be able to use the same variables two different places at the same time.
I put the code below: MC1 plays fine and MC2 does not
thanks.
skemaVars = new LoadVars();
skemaVars.load("data.txt");
skemaVars.onLoad = function(success) {
if (success) {
tegnCeller(this.startTid, this.abneTimer, this.pladser);
} else {
trace("this sucks!!!");
}
};
function tegnCeller(startTid, abneTimer, pladser) {
pladsArr = pladser.split(",");
for (i=0; i<int(abneTimer); i++) {
this.attachMovie("celle", "celle"+i, i+1);
this["celle"+i]._y = this["celle"+i]._height*0.8*i;
if (startTid>23) {
startTid = 00;
this["celle"+i].klokke = "Kl. "+startTid++;
} else {
this["celle"+i].klokke = "Kl. "+startTid++;
}
this["celle"+i].antal = pladsArr[i];
}
}
MC2
skemaVars = new LoadVars();
skemaVars.load("data.txt");
skemaVars.onLoad = function(success) {
if (success) {
for (j=startTid; j<(startTid+abneTimer); j++) {
if (startTid>24) {
startTid = 1;
setProperty(j, _visible, true);
} else {
setProperty(j, _visible, true);
}
}
}
};
stop();
Global Variables
Here is the code cut down for description:
(typing this from memory so there might be some simple syntax errors)
_global.gWeek = newArray("week1",week2","week3");
chicagoScores = newArray("7","14","21");
i = 0;
while(i < 3){
_root.bears.gWeek[i].text = chicagoScores[i];
i = i + 1;
}
This in its most simple form. I tested with a full 17 entries in both arrays of week1-week17 and scores. Both arrays work when I trace them individually. I think my problem lies here
gWeek[i].text
bears is an MC and on it are 17 dynamic text boxes each named accordingly, week1, week2,...week17.
I had tried _root.bears.week[i].text = but that failed. So I tried the global variable thinking that the [i] was causing the problem. I even filled the array with "week1.text" but that didn't work either.
I am apparently doing something wrong but I don't know what it is.
Global Variables
As you cant have true local variables in flash can anyone tell me how you deal with a variable that you want to access from a different scene?
Cheers
Global Variables Help Seriously.....
Hi all, I got a global variable that I want to see the output for using trace.
The problem is it comes out blank when I do trace. It gets it data from an xml file. I don't see how it could not get data. If I put the trace inside the function it outputs a value but not outside the function. Must I make the function global or something? Please help!
code:
_global.xValue;
_global.userInfo = new XML();
_global.userInfo.ignoreWhite = true;
_global.userInfo.load("http://localhost/gBook/userInfo.xml");
_global.userInfo.onLoad = function(success) {
if(success)
{
var root = this.firstChild
var b=0;
nodes = root.childNodes
for(var i=0; i<nodes.length; i++) {
subnodes = nodes[0].childNodes
subnodes2 = nodes[1].childNodes
subnodes3 = nodes[2].childNodes
_global.xValue = subnodes[0].firstChild.toString()
_global.xValueOne = subnodes2[0].firstChild.toString()
_global.xValueOne2 = subnodes3[0].firstChild.toString()
}
}
}
trace("Global x: " + _global.xValue);
EDIT: Changed code tags to [ as ] tags - jbum
Global Variables
Hi please help me, i have craeted a project in flash v.6 to help users create DFD's for an A2 project. As part of this i need to create duplicates of a movie clip. I used the folowing code to duplicate it:
on (press) {
_root.E_Entity1._x = 50; <--This is just to make it
_root.E_Entity1._y = 70; <--look nice
_root.E_Entity1.duplicateMovieClip("test" + I ,7)
I = I + 1
}
Then i need to make the duplicate move on drag, i tryed using the folowing line of code
myMovieClip.duplicateMovieClip(newname, depth [,initObject])
but i cant get the [,initObject]) part to work dispite trying for hours :@
so i tryed this:
on(press) {
N = "_root.test" + I
startDrag(N ,true);
trace(N)
trace(I)
}
on(release) {
stopDrag();
}
using I again so that the code would apply to the any "test" movieclip that is created, as there will be a lot.
However when tracing I and N on this peace of code they stay the same, where as when the trace is done on the first part of the code the variable I does incraese by one??????
Both variables I and N are global:
_global.I = 3;
_global.N = 3;
Whats going on, please help
Global Variables
Can someone please explain global variables to me?
I'm using Flash 5, and I've got a global (I think) variable called _whatsUp. In the main timeline, if I change this variable, using
on (rollOver) {
_whatsUp = 1;
}
on (rollOut) {
_whatsUp = 0;
}
I can get the effect I want (in this test case, to change a dynamic text field, showing the value of _whatsUp.
But, if I place the same script into a button of a mc, it doesn't do anything. What am I missing?
- b
Global Variables
I need some help with global variables. I read through a quick tutorial on them, but I guess I still don't undestand how flash handles stuff.
On frame 1 of my movie I have:
PHP Code:
set (TransPlay, 0);
Then on a button I have this:
PHP Code:
on (release) {
if (TransPlay == 0) { _root.loader.loadMovie("main.swf");
_root.trans.Play();
}
}
There is nothing else that affects the value of TransPlay yet, so it should be 0 and the condition should be met, at least by my logic. What am I doing wrong? Also, if I want to set TransPlay to 1, because my transition clip is playing, do I just do:
TransPlay = 1;
or
Set (TransPlay, 1);
Im using flash MX and if I exclude the if statement the transition will play fine, but when I include the if statement nothing happens.
Global Variables
Hi all, taking my first steps into actionscript by dissecting other people's code and reading through the Flash 5 Help files. I'm already good with timelines and basic actions, but I've decided to get a bit more involved with variables andI've been having trouble making variable global. This is going to be child's play to you I'm sure so it's won't take long:
Say I want a button action to give a variable (let's call it "ButtonOver") a value (say true or false), and make the variable global so I can reference it in code attached to another object (which I might want to set in motion). I seem to be okay with local variables but can't seem to get my other objects to respond to a variable set in another object's code. I've read the help section on global variables but it still doesn't seem to work, I sense I should paerhaps be using something more to access the variable from another object.
Say I currently have (attached to the button)
(as)
on (release) {
ButtonOver = true;
}
(/as)
and attached to a movie clip:
(as)
onClipEvent (load) {
ButtonOver = false;
}
onClipEvent (enterFrame) {
if (ButtonOver){
(/as)
(Followed by code for the action I want to happen)
Thanks in advance,
Ade
Global Variables
Is it possible to increase the value of a global variable as if like a integer?
Global Variables
I have scoured the boards, viewing threads on global variables, but I haven't found a solution to my problem.
I have a flash movie, with 3 scenes, the first scene checks for a variable retrieved through a local connection and then declares a globlal variable depending on the value of the first variable.
In the third scene I try using an if statement with the global variable, but it never works.
ex:
Code:
if (that == 2) {
_global.locate="1";
}
if (_global.locate=="1") {
// execute more code here
}
Global Variables
Hi,
I am trying to make a yes/no question game that, based on the amount of yes's or no's takes you to a different outcome.
I thought global variables would be the way to go, with script adding +1 to either 'yes' or 'no' variables everytime you click the corresponding button. Then have an If statement at the end of the movie to add up the amounts and go to the right outcome.
I've had a try at writing a script, but it is not working and I don't have the knowledge to correct it.
Anyone willing to have a look?
Thanks!
Global Variables
Hi there, I have a movie clip that loads external swf movie clips - using loadMovie() in Flash 8. The externally loaded movie clips don't seem to be able to use the root movie clip's variables!?
I.e. in the root swf file I will have _global.use_this_name = "Candrias" but _global.use_this_name is not available in the loadMovie() clips. Is there something I am doing wrong here?
Appreciate any help or suggestions you can offer.
Global Variables
the example of code below works but i can't get access to the final array once the function is done. it executes when the movie is first loaded but i need the array for other movies in it and such. how do i make it global? thanks....
Code:
_global.final_array = null;
function loadXML(loaded) {
if (loaded) {
lots.a.code.here;
_global.final_array = and_then.produce.final_array();
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("crap.xml");
Global Variables
Do anyone know how to use the variable which set in frame 1 in frame 3?
I have variable in frame 1 but want to use it in frame 3.
have anyone have any ideas?
[F8] Using Var For Global Variables?
I searched around and it was hard to find an answer to this newbie question so here it goes. I want a variable to be accessible by everything in the SWF timeline. All these seem to work just fine:
1) X=0;
2) var X:Number=0;
3) _root.X=0;
4) _global.X=0;
#2 seems like it would be speedier since it declares a type, but #1 is easier. I see everyone doing #3, and read that some do #4. Many times I forget to put _root in front of my variables, but then it works anyway. So I was thinking why waste my time typing the _root eye sore all the time? Which one is best?
Thanks!
[AC2] Global Variables
I have a flash app that has a number of scene's. Each scene represents a menu screen.
Now on one of my scenes i have this:
var controllers = new Array();
controllers[0] = "Right Keyboard";
controllers[1] = "Left Keyboard";
controllers[2] = "Gamepad 1";
controllers[3] = "Gamepad 2";
controllers[4] = "Gamepad 3";
controllers[5] = "Gamepad 4";
controllers[6] = "Computer";
controllers[7] = "None";
this gets run every time the scene is switched to.
I want this code to only be run once, so if i change the array values, swap away from the scene and come back to it, it does not get reset, and my modified values are persistant.
How can i do this?
Help With Global Variables
I really have no idea what I'm doing when it comes to this, but basically I want to create a variable that decides where the playhead goes. I think it needs to be global because I want to create the variable at the beginning of my movie, but later another .swf is loaded onto the root level.
I somehow got the idea that I should use "_global." in someway, so I attached this code to a button on the root level at the beginning of my movie:
Code:
on (release) {
gotoAndPlay("Eddie Upstairs", "Ben beginning");
_global.character = "Ben";
}
and this code to another:
Code:
on (release) {
gotoAndPlay("Eddie Upstairs", 1);
_global.character = "Eddie";
}
Then later in the movie I want that variable to decide whether the playhead goes to the frame "shotgun", or "Ben shotgun" on the root level. I also want to create another variable altogether. I attached this to a button inside an .swf that is loaded onto level 10 during the movie:
Code:
if(_global.character == "Eddie") {
on (release) {
gotoAndStop("2");
_global.go = "shotgun";
_level0.gotoAndPlay("shotgun");
}}
if(_global.character == "Ben") {
on (release) {
gotoAndStop("2");
_global.go = "shotgun";
_level0.gotoAndPlay("Ben shotgun");
}}
Totally wrong as Flash tells me, but perhaps you can get some idea of what I want to happen.
[CS3] Global Variables [AS2]
I'm trying to figure out problems with global variables and functions. My script has a set of variables it calls on to check if a user has typed in a username, or if they have anything typed in at all. It then compares the username to the database (not done yet). However, I've noticed that for some reason, the variables do not work outside the functions they are declared in, and global variables refuse to work as well. The only way the script works is if the variables are non-global, and inside the "checker" function, but I need to reference some of them outside the function.
Code:
stop();
_global.checktest = username_test.text;
_global.userbase = checktest.length;
_global.newbase = userbase-1;
numberofcards = 0;
cardnumber.text = numberofcards;
/// "Check" Button, linked to Username_test.text ///
checker.onRelease = function() {
if (_global.newbase == 0) {
errortxt.text = "Please enter your username.";
} else {
/// Check if the username entered is in the database ///
var php_process:LoadVars = new LoadVars();
var post_variable:LoadVars = new LoadVars();
post_variable.string = checktest;
post_variable.sendAndLoad("control.php",php_process,"POST");
trace(_global.newbase);
}
php_process.onLoad = function(success:Boolean) {
if (success) {
errortxt.text = php_process.result;
} else {
errortxt.text = "Error connecting to server.";
}
/// End Check Code ///
trace(newbase);
};
};
/// The Next Button ///
pageonenext.onRelease = function() {
if (_global.newbase == 0) {
errortxt.text = "I'm sorry, please enter your Username.";
} else {
gotoAndStop("pagetwo");
trace(_global.checktest);
}
};
function theTimer() {
errortxt.text = "";
}
var testing = setInterval(theTimer, 9000);
Help With Global Variables
I posted this in another forum, but no one answered.
I am creating a program in flash for an ICT project, giving people information on Plane safety.
I have a main menu page with links to each of the content pages, and 4 different content pages. When you click one of the 4 links, it uses loadMovie to load the content page into the main movie.
This all works perfectly fine, this is where my problem comes in.
I want it so there is a "close" button in the top right corner of the stage, and when you press this, it just goes to a blank page (or even takes the .swf off the .html file it is embedded in, but this isnt the issue and would take too much work as i have NO idea how to do it).
I only want the close button to work if all of the 4 pages have been loaded into the main movie. So, if a user clicks the close button and hasnt looked at one of the content pages, a messege will come up saying "you havent looked at every page, please go back and do so".
This is what I have got so far, but it doesnt work. I cant see what is wrong with it and it is driving my crazy!
Here is the code on my main .swf which everything is loaded into:
PHP Code:
stop();
holder.loadMovie("content/main_menu.swf");
_global.vcount1= false;
_global.vcount2= false;
_global.vcount3= false;
_global.vcount4= false;
In the main menu .swf, on the buttons which load each of the 4 content.swfs, I have this AS attached to them (obviously the variable name changes which each of the four buttons):
PHP Code:
on (release) {_root.holder.loadMovie("Content/content1.swf");
_global.vcount1= true;
}
On the exit_window.swf, which is loaded when the user clicks the "close" button, I have this code attached:
stop();
PHP Code:
if (_global.vcount1 = true && _global.vcount2 = true && _global.vcount3= true && _global.vcount4= true){
_root.holder.loadMovie("content/blank.swf");
_root.exit_window_holder.unloadMovie("content/exit_window");
}
else{
gotoAndStop(2)
When blank.swf is loaded, this is just a blank file that will be in place, so you cant see anything, tio give the effect of the program being closed.
The 2nd frame of this swf is an error message, saying that you havent viewed every page.
So can anyone see what is wrong with my code? I cant see where I have gone wrong, and the code should work, but I guess ive made some stupid mistake... All that happens now , is the error message comes up whether I have viewed all of the pages or none at all...
If anyone could help it would be greatly appreciated.
Global Variables
I am trying to set some variables as global in the first frame of my maintime line. under that in the same frame I am using a for loop to loadmovies into a movieclip that is embedded into a movieclip on my maintime line and it is just not working and help would be great.
_global.vinPhoto = 24;
_global.vinLogicA = "http://imgs.getauto.com/imgs/ag/ga/51/45/";
_global.vinLogicB = "/1G1JC5241Y7435145-";
_global.img = 1;
for (y=0; y<_global.vinPhoto; y++) {
loadMovie(_global.vinLogicA+_global.img+"t"+_globa l.vinLogicB+_global.img+"t.jpg", this.scrollBox.emptybox+_global.img);
img++;
}
stop();'
Please Help thanks!
|