ActionScript 3.0 :: Making Variables Defined In A Function Available Globally?

Jun 5, 2009

The following bit of code outputs that 'myRequest' and 'i' are not defined.

Code:
//Load external asset
function loadfail():void
{

[Code].....

after a bit of reading I find that it is because 'myRequest' and 'i' are defined within functions, and so those variables are not available outside those functions. How can I get around this? Make a class?

View 2 Replies


Similar Posts:


Actionscript 3 :: Declare Variables Globally Or Within A Function Only When They Are Needed?

Jul 14, 2010

I am working with URLLoader and URLRequest in this case.

I have two buttons. One listens for the mouse click event and then runs the following function (less code not applicable to this question):

function loadURL (e:MouseEvent):void {
....
var myRequest:URLRequest=new URLRequest("*URL*");
myRequest.method=URLRequestMethod.POST;

[Code]....

The other button, when clicked, calls another function, say resetAll, that then resets the "session" by clearing out all the current variables and canceling anything currently in progress. Within that function I want to call myLoader.close(myRequest); but myLoader is not accessible from within resetAll.

In this case, should I declare var myRequest:URLRequest=new URLRequest("*URL*"); and var myLoader:URLLoader = new URLLoader(); outside of the function even if I do not need them yet?

View 3 Replies

Actionscript 3 :: Function Running Before Variables Are Defined?

Jun 15, 2010

I am trying to add an init() function to a MovieClip, but when I run the function from scene1 the variables that were set in the MovieClip are not defined yet... The MovieClip was dragged to the stage from the library.scene1:

mc.init(null);
MovieClip:
var _default = 5;

[code].....

View 1 Replies

ActionScript 3.0 :: Accessing Variables Defined In A Function?

Aug 10, 2009

I have been playing around with combining flash and PHP/Mysql for some time now, mainly sending one flash variable to a PHP file and then retrieving a result and turning it back into a different flash variable. My problem is i've got to the stage where I need to access these variables from other functions. Now I think I need to find some way of defining them outside of the function, maybe using global vars? Well i'm not gonna pretend I know anything about it. The two functions from which I access my PHP variables is as follows:

ActionScript Code:
function btnDown(event:MouseEvent):void {
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("http://localhost/test.php");

[Code]....

So I need a way to access the phpVar1 variable in a totally seperate function

View 6 Replies

ActionScript 2.0 :: How To Access Variables Globally

Nov 2, 2007

i assigned some variables called charstrength and so on but i want to access these variables globaly as the action is on the first frame with all the variables stated and on the second frame i need to access those variables but it just wont let me.

View 9 Replies

ActionScript 2.0 :: My Global Variables Are Not Behaving Globally

Feb 4, 2010

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]...

View 5 Replies

Actionscript 3 :: Flash Run A Function Only If Instance Within Function Is Defined

Mar 3, 2011

I have a situation where, upon loading my swf, I add an event listener to the stage to listen for keyboard commands. One of them is to listen for the spacebar, and if it is pressed, it should play a movie. The problem is, that movie is not loaded until later on, depending other user interactions, therefore, until it is loaded, the reference to it would be undefined.

But if I wait and add the listener for key commands only when the movie is loaded, then I can't utilize the listener for other keyboard commands, like RIGHT or LEFT, which are the buttons which get you to the movie in the first place. Is there a way to add a conditional or something to prevent that code from being executed if the video is not defined yet? Here's my code:

[code]...

View 2 Replies

Arrays :: Flash - Defined Within A Function Discarded At The End Of The Function?

Jul 6, 2011

Curious question:Take this function:

function something():Array
{
var ar:Array = [];

[code]....

View 2 Replies

ActionScript 2.0 :: Variables Not Staying Defined?

Jan 15, 2009

All of the variables that i define in frame one appear to no longer be defined in frame 2.

Here is a snippet of the actual code from frame 1 and frame 2 in case I'm missing something.

Frame 1:

ActionScript Code:
function init() {
var markedFrom = myVariables_xml.firstChild.childNodes[0].firstChild.nodeValue;
//trace("Marked From: " + markedFrom);

[Code].....

View 9 Replies

ActionScript 2.0 :: Variables Defined In A Compound?

Sep 28, 2010

What I mean by that title is, how would I define a variable name, with a variable, and some text, for example.

ActionScript Code:
var i:Number = 0
var ["test"+i] = "Test"

Where i changes to continually give me different variables, and, in this case, I would have the variable test0.

The above gives the error "Identifier expected". Oh, and it would also be useful to know how to do it in AS3, but I mainly need to know it for AS2.

View 2 Replies

ActionScript 3.0 :: Variables Defined Inside Of Other Functions?

May 3, 2010

Trying to find the best way to use the xDoc variable in the newImg function without adding the newImg eventListener to the xmlLoaded function

var myXML:XML;
var xDoc:XMLDocument;
var xmlLoader:URLLoader = new URLLoader();

[code].....

View 5 Replies

ActionScript 3.0 :: Using And Changing Externally Defined Variables?

Aug 23, 2009

The problem which i have is about using variables (specifically "myVar") defined in one as3 class file, in a separate class file. After searching for this via google and on this forum i have not (maybe because i have been searching for the wrong thing), so here is my situation which i think should be simple to solve:Inside a fla called "Main" i have 2 MovieClips. The first is called Main and has a class linking to the com/Main.as file which has this code:

ActionScript Code:
package com{
import flash.display.MovieClip

[code]....

View 6 Replies

ActionScript 2.0 :: Check If Variables Values Are Defined?

Aug 29, 2005

it's not working. why not?

[Code]....

View 8 Replies

ActionScript 3.0 :: Accessing Externally Defined Variables?

Aug 22, 2009

Here is the problem:I have 2 external as3 files in a "com" folder next to the FLA within which i am working. The first of these ( "Main.as") is the document class. The second ("events.as") contains variable definition "myVar:Number = 0" which i want to be able to access and change inside Main.as. I am sure that this is possible, but i can't get it working (flash very keeps pointing out that I have made an error. Specifically that old classic: "1046: Type was not found or was not a compile-time constant: myVar." which has puzzled me since the dawn of time.

View 3 Replies

ActionScript 2.0 :: Get Global Variables That Are Defined Inside XML Array

Aug 22, 2007

I've been trying to get these variables that are defined inside this XML Array, outside of the XML array using _global, so that i can use them else where in the animation, but i'm not getting any purchase.

[Code]....

View 2 Replies

ActionScript 1/2 :: Evenly Spacing Dynamic Text Fields Defined By Variables?

Aug 4, 2010

What im going to be doing is replacing the bottom info with just a link-strip, unfortunatly I didn't want to have to sift through ten dynamic text fields re-animating every one with tweens to the way I wanted them so I set them all to a parent variable defined as "mt", such variables being as follows:HomePortfolioDocumentationDev BlogCase StudiesSupport For

View 4 Replies

ActionScript 2.0 :: Combining Logical Operator With Variables Defined By Radio Buttons

Aug 7, 2008

I have completely hit a wall. Here's what I'm after. I have two sets of radio buttons, each of which controls what loaded swf appears on stage. Then, depending on which button is clicked in group one and which button is clicked in group two, a third swf appears. I can access the value of each radio button, and I'm passing it into a variable (I think - the trace command works) but when I drop it all together into an if/else statement, no data is passed.

Here's the code:
//printArea is a movie clip on stage, which has dynamic mc's attached via code
var thisFront;
//function for what happens when fronts radio buttons clicked
frontListener = new Object();
frontListener.click = function(evt) {
[Code] .....

View 3 Replies

ActionScript 2.0 :: Calling Function From Root That Is Defined In MC?

Jan 1, 2006

i've got this mc component i've created and reuse on some sites i've made. It's a real simple shoutbox that grabs info from a database using a php script.What i'd like to do is have this component refresh every 200 frames, which means, grab most current msgs and post them in the database.so for example, i have a movieclip called MC1. there's a function in MC1 that goes like: grabdata = function() {}; this basically calls the php scripts, loads the info, and so on.i wanna call this function from the root or even a parent MC.I have considered using prototypes or a class, but i dont think it's really necessary for something that seems basic enough.

View 1 Replies

ActionScript 2.0 :: Calling User Defined Function?

May 27, 2009

I am trying to load external swf's into my main swf through nested movieclips.Its like this: STAGE > contents_mc > loader_mc Also most of the code is from tutorial's out on the net.Content_mc I have the following MC's in content_mc (on 2 separate layers, if you want to know):

- Preloader_text (PText)
- loader_mc (LoaderExt)

[code]...

Problem: I am having a problem in calling the function ClipLoader and loading a clip through the loader_mc MovieClip (the text in Purple). The reason I am using this is eventually I will put in code in contents_mc to load various external swf per conditions i give.

View 7 Replies

ActionScript 3.0 :: Passing Instance In A Dynamically Defined Function

Feb 20, 2012

I'm trying to define this function so I can pass the CardButtons sprite to the Add Cards function. It "works" but there's one problem: the CardButtons sprite used in the function is determined by the value of i at the time of the function call (or in other words, the value of i when I click the sprite).
 
I want the sprite passed to be literally the value of CardButtons[i] at the point when the function was defined.
 
CardButtons[i].addEventListener(MouseEvent.CLICK, CardFunctions[i]= function(){ AddCards(CardButtons[i],PlayerHand[player-1][PlayerHand[player-1].len gth-1]);});
  
Is there a way I can do this, or is there a better way to do what I'm trying to do?
 
I guess for further example:
 
I want CardFunction[0] to store the AddCards function with the value of CardButtons[0] passed, it should NOT be dependent on the value of i.

View 3 Replies

JavaScript :: SWF Object - Play Song Function (Not Defined)

Sep 4, 2010

I'm trying to have JavaScript call a function from my ActionScript.

ActionScript:
import flash.external.ExternalInterface;
ExternalInterface.addCallback( "playSong", playSong );
function playSong():void {
var _sound:Sound = new Sound();
var _request = new URLRequest("music.mp3");
_sound.load(_request);
_sound.play();
}

JavaScript:
swfobject.embedSWF('[URL]', 'musicplayercontrol1', '1', '1', '9', null, null, {
allowScriptAccess: 'always', wmode: 'transparent' }, { }, function( e ) {
document.getElementById('musicplayercontrol1').playSong();
});

I keep getting a function not defined from firebug. I tried having the song play as soon as the swf load, and that works for sure.

View 1 Replies

ActionScript 2.0 :: Reffering To This From Function Defined Inside Class?

Jan 18, 2006

Code:
class className () {
//constructor
function className(targetmc,linkId) {

[code]....

My question is how can I set up an interval when I click on a button that is created from within the class.

I need my function updater to keep repeating untill I clear the interval.The only way I can figure out is to give the full path like this._parent._parent.instanceName.updater inside the setInterval, but although this works I think is just dumb to hardcode the instace name of the class. I could of course try to pass the instance name as a parameter, but I would really love to find out the smart way to do this (by the book).

View 3 Replies

ActionScript 3.0 :: 1061 Error (not Defined) When Call A Method Of A Self Defined Class

Feb 9, 2010

I am using flex builder 3.2, Action Script 3 and develop for Flash Player 10 and am quite new to it. when I call a method of a self defined class, I get the 1061 error (not defined). But the class and the method exist and are public, so what the hell am I doing wrong? Flash Builder is even offering me this method in the auto-completion, so at least the builder knows it... I have already tried cleaning the project (as this is the common source of strange errors when working with java/eclipse),

edit: solved... The problem was that a package had the same name as the variable I used for the class. Very strange error message, thumbs down for this .

View 0 Replies

ActionScript 2.0 :: Scope Concept: How To Call User-defined Function

Jul 15, 2009

i am quite newbie towards to actionscript 2.0 cos i am now learning on actionscript 2.0
here is the file attachment for you to check.Greetings.zipOutput cannot be worked.I am hoping to see the exact output:Greeting = Hello!Salutation = undefinedSubject: Brick Oven

View 2 Replies

ActionScript 2.0 :: Call A Function In Main Timeline And It's Defined In The Button?

Sep 28, 2010

I have a main time line and a button defined. Can I define functions in actionscript anywhere and call them from anywhere? For example, if I call a function in main timeline and it's defined in the button, does that work?

View 3 Replies

ActionScript 2.0 :: Function Not Defined Immediately After Create MovieClip Instance

Jul 14, 2004

I create a new MovieClip, call it Somehow, and link it to the name "MyClip", for example.[code]...

They must be MovieClips, because the functions not only response with hello, like in the example.

So I want to create the Clip copies and call the functions in one step. This example is also not working when i put it inside of a onLoad, or onEnterFrame and so on.

View 5 Replies

ActionScript 3.0 :: Can Pass Touch Event To Class Defined 'global' Function

May 12, 2011

I have a class file defined in my package as MyGlobals.as.[code] (I have tried adding/removing "static" and "dynamic" to no effect.)I am trying to call a touch event from the main timeline in this way:myObject.addEventListener(TouchEvent.TOUCH_BEGIN, MyGlobals.myFunctionName);(I have tried removing the class name to no effect.)When I compile I get the error 1046: Type was not found or was not a compile-time constant: TouchEvent. This error occurs on function definitions in the class file.What syntax/concept am I getting wrong? The functions were working fine when I was using constants in the timeline, but I need to be able to reuse these functions over and over again, so I wanted them to be able to take touch event variables so that I didn't have to write a different function for every touch event.I tried googling "error 1046" but I can't find anything useful.

View 3 Replies

Javascript :: Soundmanager2 IE Playback - 'onload' Callback Function Is Defined As Null

Apr 5, 2012

I'm currently working with soundmanager2 in an IE/flash context (not html5). The issue is that audio playback of mp3 content does not occur for the following case where the 'onload' callback function is defined as null OR as a function that does almost nothing.

[Code]...

View 1 Replies

Actionscript 3 :: Flash - Function Defined In A Keyframe Re-loaded In Memory Each Time The Frame Is Visited?

Aug 12, 2010

In Flash Actionscript 3, if a function is defined in Frame 1 of a flash animation and the animation loops, does it store another version of the function in memory upon each loop.

[Code]...

If so, is it a best practice to check to see if it's the first time the frame has been run, by setting a variable and checking it's existence, or is it a non-issue because the compiler checks to make sure that a function has not already been defined?

[Code]...

View 1 Replies

ActionScript 2.0 :: [mx] Making Variables Available In Streamed Movies?

Jan 11, 2011

I am loading various movies into a "shell"movie as and when they are needed using loadMovie... However I have one movie which I am loading in to the shell "holder" movie which is supposed to load in variables from a php file. Now when this swf file is run in the browser outside of the shell, it loads in all the variables just fine. The loadVariablesNum command loads into "0" the root timeline, but when I run the shell and navigate to the swf file, none of the variables appear.I am guessing I need to load the variables into 'this' movie, but I have tried that by using the complete path...

_root.holder_mc.loadVariablesNum("scorevars.php"," post");

But this doens't pick up the vars. My problem is I am not fully understanding the relationship between swf's loaded into each other and how the timelines interact...

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved