ActionScript 3.0 :: Making A Local Variable Global?
Sep 7, 2011
I have a problem where I make a variable in one class and change it using the constructor method in another.Is there anyway that I can make that variable available in all methods in this class? Here is the code:
I mostly use flash for the animation, so my action script tends to be mostly functional.
I am now however having an issue, i am using a variable called language which I am setting in frame one as "dutch", "english" , "german" etc... Im then using this to set dynamic text as appropriate in each frame as necessary.(and yes i may switch this to case statements )
if (language == "dutch") { tcMC.peasantBubble1.peasantSpeech.text= "Bescherm je een schat?"};
My problem is however that one Movieclip does not see the language variable.
Is there anway in CS4 i can direct it to where it is, or define the varibale instead to be global (perhaps id have to change it from a string though)?
i defined the global variable in the first frame of my file, and i can access it on other frames, however i am trying to access it within a movieclip, and flash is telling me that it is undefined. does anyone know why this could be?
I have a movie clip on my stage and it is named quest. Within quest, there are several frames representing the entire game (it's a text based adventure). Every once in a while, there will be an inventory item in one of those frames that has the ability to be dragged and dropped into the inventory box (which is a seperate movie clip on the main stage).
All of that works fine, however, since the movieclip that can be dragged was defined in the 'quest' movieclip, once the user needs to move on to the next frame in the quest panel, the inventory item disappears from the inventory box.
in my Controller Class:[code]brick it's inside a container and its position in x axis is 200px.When the brick is moving, the x and y value are based on stage x and y mouse.The 0 in the stage should correspond to -200 inside my container.How can i use globalToLocal method?instead write:brick.x = (mouseX - mouseX%theGrid.getGridSize())-200;
I have this movie clip on a stage that I need everything to be center on stage even after resize.the clip structure is rootclip.child.child.the first time I click the button the tween works fine. If you click a second time the clips start start to drift away from center stage. And if I resize the stage everything seem to fall apart. the 203.5 is half the width of the MC that I'm trying to center. So it's total width is 407px.
ActionScript Code: this.startButton.onRelease = function () { var introHead_currentPos_x = _root.instructMc._x;[code]....
I made a cube with as3. I wanted it to rotate in the Y Axis according to the horizontal mouse movement. It works nice when this is all I want. But if I try to also make it rotate on the X axis with the vertical mouse movement, things get screwy.
This happens because the transformations are added in the global coordinates, not the local ones. So, for Example, if I wanted the cube to rotate 30 degrees along its Y axis, I have to find a way to translate that into the global coordinates, and then apply that to the matrix3D of each face. I need a local to global translator.
I wonder if a keyframe on an actions layer that has an action in it will work like a keyframe on other layers, meaning it will make all actions on the previous action frame inactive and only the actions on its corresponding action sheet available.If that is the case, is it possible to have at least two action layers to separate global and local actions?
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.
Is this possible AS3? I've been searching everywhere for a way to make Movieclip Instances globally accessible and haven't had any luck.I know I can make variables global by making them public and static in the class constructor, but I can't find a resource for objects.
I hear this is typically bad form, but I have a portfolio site where the entire site and it's contents change scale and position for every thumbnail.If I could make things like the BG, border, header, footer etc. globally accessible, I could change them all with a one or two global methods.
how you would target a function's local variable through a concatenated variable string.For example:
var txt = "Hello World"; function testing(msg) { var test1 = msg;[code].........
I'd expect the trace to be "Hello World" but rather is given "undefined". So if variables created outside functions are created on the main timeline, where are local function variables created and how would you access them?
I have a LoadVars object called loadText in which an external variable is loaded from a text file. Now, the whole thing works, I just want to create a template to optimize the system, so here is what I need: The external variable (in an external text file) is called page1. I am assigning that external variable to a local variable (at this point the external text has already been loaded in loadText, of course):
I was trying to convert global coordinates to local coordinates of a UIComplenent in my flex project using below code using below code
var gp:Point = new Point(e.stageX,e.stageY); //global point var lp:Point = uic.globalToLocal(gp); //local point
uic is UIComponent in which I have subclass of Sprite for drawing something I have set the sprite's mouseEnabled and mouseChildren to false to not interrupt the mouse event. above code is within uic's mousemove event where I was tracing the gp and lp gp was giving correct value and suprisingly lp was giving negetive values. when I move the move to the top left corner of uic i expect lp to be 0,0 but it is giving the -width of of uic. I broke my head for hours and ended up finding an alternate by using offsets. Infact my original code was much simpler like this which was same issue
var lp:Point = new Point(e.localX,e.localY);
I am not sure what exactly is causing this problem. the workaround had lot of issues and it creating a mess in my rest of the algorithms.Just now I found even more interesting thing (which is actually weird). for some reason I went and create a new lp2
var lp2:Point = new Point(e.localX,e.localY);
now surprisingly it was giving correct values as expected and I went back and changed the code as
var gp:Point = new Point(e.stageX,e.stageY); //global point var lp:Point = uic.globalToLocal(gp); //local point var lp2:Point = new Point(e.localX,e.localY); var lp2:Point = uic.globalToLocal(gp);
now it is expected to have all the lp, lp2 and lp3 variables to be same but weiredly lp two is giving wrong value and lp2 and lp3 were giving correct. I am suspecting using the variable lp has something to do. I am not sure about that but above proves it so right now I am using lp2.
I'm trying to get a value from a function which is a URLLoader COMPLETE event but even with declaring variables outside of the function will not allow me to get the value out. I'm stuck.It seems that the Asynchronous nature of Flash makes it impossible to get a value out: e.g. this works:
// Initialise a URLLoader to get XML data from XML file var myFPBLoader:URLLoader = new URLLoader(); myFPBLoader.load(new URLRequest("flightPlannerBoard.xml"));
I want to make an application that loads some images with a Loader by making URLRequests to a local folder. Can I build the application and include somehow this folder so when I send it from a server to a client the URLRequests operate normally on clients side? Also if this is possible, the folder may be not viewable/accessible by the client but only from the Flash application that comes with it? So for example, this piece of code that runs nicely, locally, to my machine, if i send it to a client will continue to run to its machine. Can somehow send the folder and the SWF as one object?
private function clothesOn( outfit:String ) { var clothier:Loader = new Loader(); var item:String = "clothes/" + outfit + ".gif"; var getItem:URLRequest = new URLRequest( item ); clothier.load( getItem ); this.addChild( clothier ); }
I have a movieclip on the stage, and in that clip I have a button that is supposed to turn a global variable from true to false, but the compile tells me: 1119: Access of possibly undefined property root through a reference with static type Class.
When I use this code: Code: function closeMSN(event:MouseEvent):void{ this.visible = false Stage.MSNOpen = false }
I know how to reference the movieclip itself by this, but how do I change the value of a variable on the main stage, from inside the movie clip?
i've declared global variable in the first frame of the main timeline:var cLabel:String;In the inner timeline of a MC, i use this code:stop();cLabel=this.currentLabel;but flash gave me error 1120: access of undefined property
I'm having an issue with a global variable. I'm trying to give it a value within a function and it isn't working.The variable is imageList. It's an XML List. I'm making it global so I can use it anywhere in my project. I suppose if someone has a better idea to avoid the global variable, I'm up for that too. But for now, it seems like the way to go.
Here's my .as file: package { public class MyGlobal {
[code]....
It's giving me the same same Error #1009 as above. It seems like a scope problem, but why? Shouldn't it work since it's a global variable?
defining the variable i:e frName.... outside the function it does not display anything..same time if I define same variable inside function i:e disp_fruit...it displays the name ]why?
and how can i use variable i:e frName as global var so that it can be used in any function?
I have a stackview of textfields and when I type into the text field I want it to update on each stackview "page", kind of like a global variable, maybe even using a global variable.
Can I bring in a variable (saved in a text file) using LoadVars and then make that variable accessible from anywhere in the script (i.e. make the variable a global)?
I have a button in a movie that I want to set a global variable to a new value when clicked. I want it to access a parameter of a movie clip that this same button loads onto the movie for the new global variable value. I have the final line under this button's onrelease script with something like this:
globalvariable1 = movieclip.parameter; Everything is on level 0 and I've tried prefixing everything with _root. but it didn't make a difference, the global variable still wasn't changed. I'm a newbie so don't laugh if this is a really dumb question!
here is the set up. I'm working with three files. Main.swf which contains navigation.swf in a blankmc, empty mc called mcContent where navigation sleclected materials are loaded.
In the navigation.fla here is the code [AS]trace("now defining global"); _global.loadFile_str = strPicName;
I want to load an external .swf into my main .swf, it will contain a textfield. However, in order for it to know what to put in that text field, it must pick up on a variable main.swf_global.USERENTRY now in order for my mc user_output to display _global.USERENTRY, what must I do?
I am trying to use the global variable declaration. Up to know I've been using the x coordinate of a movie clip to pass variables between different movies, and I thought it was time to learn properly! Just to get it to work, I am trying a flash file with two movies in the root. One movie defines a glabal variable on load; _global.numb = 6;
And then I am trying to just get the other to trace it on enter frame, so the code attached to the other movie (on enterframe) is... trace(numb); (And I tried trace(_global.numb) as well, but I was under the impression that you only had to define it as being a property once.). All that happens when I run the movie is nothing is traced.