ActionScript 3.0 :: Local Variable Physically Exists (in Memory) Outside Of The Function?
Dec 23, 2010
1- Variable Scope : Accessibility and existence are used almost interchangeably in various documents I've read. I'd like to know if a local variable physically exists (in memory) outside of the function it was declared in, and is not accessible from other methods, or if its existence ceases outside the function.
2- Classes : When do you create an instance of a class versus importing it only, specifically in the case of classes used only as say, calculators ?
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 wonder what the most common reasons for memory leaks in AS3 are.First thing what I am not sure about is: is it better to have a variable reference inside a function or outside it. Will the variable be null-d automaticly inside a function or when do I have to null it and when not?I have massive problems with my game with memory leaks. I noticed I reference some of the clips of the timeline even inside my debugging clip to display propertys and this was causing collecting huge amount of memory.But even before I go into the game with bigger objects the System.memory is slowly growing and growing.I just have a socket connection and some interval loops and enter_frame events.
I want to load an XML file and access one node value. I decided to store it in a variable(var addedNumber).
The problem is I want to access this variable in a new function (loadURL)"outside" of the scope. Is there a clearer way to do this instead of using nested function?
PHP Code:
var XMLLoader:URLLoader; var XMLPath:URLRequest; var XMLDoc:XMLDocument = new XMLDocument();
if (XMLData.product[i].image[0].thumb) {thumbURL = XMLData.product[i].image[0].thumb;}Returns: TypeError: Error #1010: A term is undefined and has no properties.Same withif (XMLData.product[i].image[0].thumb!=undefined) {thumbURL = MLData.product[i].image[0].thumb;}
I'm getting the "Error #1009: Cannot access a property or method of a null object reference." error on my application. Is there a function I can use to detect this before it causes an error... maybe something like:
isValid(variableName);
I know there's one, because i've used it before, but i can't remember what it is right now.
In flex, how to check if a variable exists? I have tried using
if (this['some_variable'] != undefined) { //do something }
There is a run time error saying the property some_variable does not exists. I have checked with null instead of undefined, still the same error.
Based on the replies I have used this.hasOwnProperty('variable_name'). I found that its returning true if variable_name is a public but false if its private/protected. How to check for a private variable?
I'm attempting to make a platform game. Each level is contained within it's own MovieClip, which has it's own class. Each of these classes extend the Level class, which provides basic functionality for all levels.
Each individual level has a numPlatforms variable which stores the number of platforms in that particular level. I currently have a for loop that runs from 1-numPlatforms and sets the level area (the image, more or less) the platform contains:
[Code]....
Is there any way to check if a variable exists within a MoveClip? I've trying comparing it to null and also to undefined, but neither works.
Wanted to know if it is possible to make a bool-variable in flash that is set to 'false' by default. It then checks if a file exists at a certain location, and if so, the bool-variable is set to 'true' ? Something like: if (c:/myTextfile.txt == true){*do stuff here*;} What would be the correct code?
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 have done some reading up on it and could use some further clarification if anyone has a few moments to enlighten me. I would like to understand how paths work inside a function. Question 1: Is it possible for a function to discover what movieclip it exists in? When i trace(this) within my actionscripted function it returns object Object. (sorry code is on another machine)
Question 2: When I am attaching a function to _level0.myMainClip.mySubClip from _level0 timeline in actionscript and I use "this" within that function am I refeering to _level0.myMainClip.mySubclip? or the function within that movieclip or _level0 since that is where I am creating the function?
I am trying to access a button that has been added to the stage to change it's alpha value.I'm changing it from inside an object that is also on the stage.So I thought this.parent.feed_btn.alpha=0 would work but flash is saying:1119: Access of possibly undefined property feed_btn through a reference with static type flash.display:DisplayObjectContainer.I would actually prefer to remove it, but removeChild threw up the same error.
I create a lot of banner ads for my work and they vary in small and superlarge sizes with product/price info. We recently upgraded to CS 5.5. and I am now working on setting up my workflow as a project to be more efficient.The smallest banner is 300x95 and the biggest is 980x500 - just to demonstrate the size difference. They should both have the same productinfo inside and I would love it if I could have one assetfile for all product info - including the product image - but because of the obvious banner filesize issues I can't just drop a 500px tall image into the assetfile and use this on all bannersizes because even if I scale it down in the smaller banners Flash will still export it as a 500px tall image.Is there any way in Flash to physically downsize the file when scaling it?
It kind of functions like a shopping cart / product calculator.
I want to be able to physically save a file with text data (to be reloaded later) in a directory on the computer. the app is running form a projector on windows.
when i write prototype method and declare a variable inside the prototype method. this is fine but as sonn as i declare another variable with the same name i get an error. conflict with "variable" namespace internal. i've contact other users and they claim they don't get this same issue. i'm using flash CS3, i have flash player 10 installed but cs3 only supports up to 9 so i have 9 selected. and i'm using AS3. this is some code you can use to test to see if you get this issue:
I have a question regarding AS3 memory management. Supposing I created an instance variable for a Class, in this case or type Sound: public class SoundStore extends Sprite{ var s:Sound; Then within various class functions I referenced this variable multiple times, each time I wanted to load in a new sound: s = new Sound(); Am I correct in thinking that each time I created a new Sound I would be overwriting the previous allocated memory?
I made a memory game with a tutorial. My knowledge of AS3 is not that good so I have to following question.There is a function like Math.Random to random generate number and put them on stage. I made a memory game and the cards are on the same place every time I play the "movie".I want them to shuffle every time I restart the game. How can I write a good random function in AS3?
How to access a local variable from another class? I have this powerup class that changes the speed value of the enemy in enemy class(it's a game). For instance, if player hits the powerup it changes the local variable 'speed's value inside enemy class.
I have 2 methods in a actionscript class.[code]I get duplicate variable warning. Is the local variable scope not limited to the method. Can't I declare same name variable in multiple methods?
if I use in statement xml-child distinct of nameWin (summa, e. g.), it works good. But with nameWin, e4x compares local variable nameWin (which not interested for me at all at this time) with "necessary name" instead of compare item's nameWin with "necessary name".