ActionScript 3.0 :: Use Variable Outside Of Function?
Jul 5, 2010I'm using the following class as part of my project:
Code:
package {
public class getData extends main{
[code]......
I'm using the following class as part of my project:
Code:
package {
public class getData extends main{
[code]......
I have a public variable and I am trying to set it, then read it from a different function:
public var str:String;
public function DailyVerse()
{
function create() {
[Code]....
My trace results says null. Why does it not give me "hello"?
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'm trying to combine PHP/SQL and Flash. I've got a problem now. I want to load a variable that contains an url to an image. so the variable is like this: [URL] Now I want flash to load the image, not the text. The variable is called 'img1' but the loadmovie function doesn't work when I put it in.
View 2 RepliesI want to monitor a variable. Whenever the variable value changes I want to call a function. In actionscript 2 I can use "watch" but in as3 what can do ?
View 1 RepliesI have a set of Cue Points in an FLV I'm playing. It's an interactive quiz, so the idea is that flash will change a variable, theAnswer, to a different letter depending on which question it is. The answer to question 1 is B, question 2 is D, etc. Either the cue point event listener isn't working, or else it is working and Flash isn't declaring the variables. 1120: Access of undefined property theAnswer. I literally can't find a single problem with my code. I have an almost identical Event Listener further down which works.
[Code]...
is it possible to declare function this way
ActionScript Code:
function startShake(e:MouseEvent, num1, num2):void
what i mean is it possible to send to the function not only en event but also a variable and a second question how can i access
ActionScript Code:
function stopShake(e:MouseEvent):Array
this array that function return.
I need to pass a variable to a function inside a function. However this parameter (i) seems not to be passed (to function ...onRollOver). This is required to attach a textfield to a movieclip (reading the adress and showing it as a tooltip).
ActionScript Code:
for (i=0; i<array_BE_ElecCities.length; i++) {
var attachElecCity = mc_map.mc_places.attachMovie("Plant",
[code].....
I want to create a vector, then call a function that populates that vector with arrays. Fine. The only catch is the function itself will declare new array variables to put into the vector, but are these new array variables private to the function only?e.g. something like this
ActionScript Code:
public var vec:Vector.<Array> = new Vector.<Array>();
private function populateVec():void {
[code]....
Is this "kosher"? a was declared in the private function but added to something outside the function..?
I have taken variable in one function and want to use that value in another function.
View 2 Replieshow to get variable value from a function to a text box here is the code :
import fl.controls.ComboBox;
import flash.events.Event;
import flash.events.MouseEvent;
TxtAnswer = Array();
[code]....
.. i want that variable "sk1" to next scene text box ..i putted the code like this :
q1.text = sk1;
but it is not working..
me how I can use the variable from one function in another function?
For example:
function init():void {
var test:Number = 1;
}
[Code].....
I have created an actionscript function which stops an animation on a specific frame which works fine. I have then loaded in a php file with a variable which will contain the number for the frame i want the animation to stop on. This has loaded in fine and i have loaded it in a function. what i cant seem to do is to get the variable into the function which tells the animation to stop playing.
here is my code:
//load variablesvarReceiver = new LoadVars(); // create an object to store the variablesvarReceiver.load("http://playground.nsdesign6.net/percentage/external.php");//load variables
[code]....
I have this code:
for each(var tool in tools){
tool.addEventListener(MouseEvent.MOUSE_DOWN, function(){
trace(tool); //Always the last tool
});
}
How do I bind the value of tool to the function so that it's accessible on callback?
Can't seem to get the value of myXML outside the function, despite being declared outside. The data loads and traces correctly inside the function.
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("flightPlannerBoard.xml"));
var myXML:XML;
// Check XML data fully loaded
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
myXML = new XML(e.target.data);
//trace(myXML);
} trace(myXML);
I have successfully passed a value to my function using another class.how do i know it works? Because when I put the trace statement in that function it gives me the value of the passed value.Now I want that value from that function to be get or to be used IN OTHER FUNCTION WHEREIN THAT FUNCTION IS ON ENTERFRAME. But I cant for some reason._a is a global variable
ActionScript Code:
package {
import flash.display.MovieClip
[code]......
I'd like to have a number of different functions named something like: "function1", "function2", "function3", all the way up to function100.
I'd like to be able to call them by adding the the number as a variable. For example:
type = 2;
function+type();
Which would call function2. I'm trying to avoid a huge if/else statement by only calling the functions I need.
Can a function be called if part of the function name is a variable? Is there another way to join "function" with the variable and then call it?
I have a array that gets passed straight into this function
Code:
function handleResult(re : ResultEvent)
{
QuestionSet = re.result;
trace(QuestionSet[0]['Question']);
}
Now I wan't to take the 'QuestionSet' array out of this function and expose it on the first frame (or on the _root. domain) so I can call it from OUTSIDE the function. So for example:
Code:
function handleResult(re : ResultEvent)
{
QuestionSet = re.result;
[Code]....
I can't just return the array because first i need to PUT IN the array in order to return it from the function which defeats the purpose!
Just get "undefined" with this:
Code:
hide_current = function() {
trace (_global.Klikk._y);
}
_global.Klikk is "mc_frontpage", which is the name of a movie clip i want to mess with.
Is there a way to reference a function via a variable? In other words, instead of saying something like:
var theVar = someString + 'function';
if (theVar == 'functionName') functionName ();
to access it directly:
(someString + 'function') ();
using some kind of bracket notation?
i have a function inside another function. Here is a structure of my code:
Code:
function loadXML(loaded) {
if (loaded) {
timer = new Array();
[code]....
As you can see, I declare timer array in the main function but I also want to use it in another function inside the main function. I have tried to call _root.timer and this.timer but it returned me undefined.How can I call it to use? Or how can I declare it properly?
I am having trouble getting a variable from within a function displayed. Basically I have a combo box, and want to pass the value of that to a global variable, but is does not seem to pass it.I have the following code:
PHP Code:
form = new Object();
form.change = function(eventObj) {
[code].....
I have 3 movieclips in the Libarary, called (both by name and class) section0, section1 and section2.This works for instance to attach a movie clip to the stage:
Code:
var myMovie:MovieClip = new section1;
addChild(myMovie);
[code].....
how I can pass a variable calculated in a function, to the stage.
View 9 RepliesI've tried to make a function that will allow me to change the value of any variable in my flash movie, but it doesn't seem to be working. Here's my current code:
PHP Code:
function changeVar(variable,varValue) {
variable = varValue;
}
changeVar(score,"50");
I have a variable which needs to be updated upon user input. It works inside the function, the trace function returns the correct type, but for a reason it wont pass it on the variable on the main timeline.[code]
View 5 Repliesi have a function that read a variable from a text file, yet i can only read the variable from within the function. How could i create a global variable or such that i can then read from outside of the function.
Code:
var Make:LoadVars = new LoadVars();
Make.onLoad = function() {
VARIABLE = Make.textVariable;
[Code].....
I have the as file attached to stage, and I would like to use the variable and function from that as file inside a movieclip. Unfortunately when I called up that function or trying to use variables it would always say the function or the variable is undefined. Is there a way to access the variable and function from as file?
View 1 RepliesWhat is the ActionScript 3 function that returns the type of a variable ?
I remember that there is one but I can't remember it nor can I find any reference of it.
Trying to create a random movement for fish MCs:
//----------------------
var deg2rad:Number = Math.PI / 180;
var speed:Number = 1;// set to speed you want
var numFish:Number = 4;
[Code].....
Problem I have is that they all move to the same angle (the last one created).
How do I pass the different "my_angle" values to the "move_me" function...?