ActionScript 3.0 :: Use Of Local Scoped Vars In A Static Block?

Feb 6, 2010

it doesn't seem like you can use locally scoped vars within a static block?For example I was thinking I could do:

Code:
public static var standardAgeRange:ArrayCollection = new ArrayCollection();
//static block
{

[code]....

but apparently I have to first declare _n as a static var of my class (or as a static var within the block itself) in order to use it within the static block.needed to do...

private static var _n:int = 2;

then in the static block:

for (_n=2; _n<120; _n++)

In Java I'm able to use locally scoped variables within the static block. I know this isn't Java, just wondering if I'm missing something fundamental. (I couldn't find a lot of documentation online concerning static blocks in AS.)

View 1 Replies


Similar Posts:


ActionScript 3.0 :: A Proper Solution To Using .this And Static Vars?

Oct 27, 2010

I'm trying to call a function in my main class's .as file from a sub-one.However, the function (in the main class called "makeTurret") needs to add it as a child to the main class. However, to access it from the sub-function it needs to be a static public function (to my knowledge).Because of this, I can't use this for the root.UNWORKING code (Specifically the makeTurret function at the bottom):

Code:
package
{
import flash.display.MovieClip;
import flash.display.Shape;[code].....

I used a "GlobalVarContainer" thing as suggested in this blog post: greenethumb.com/article/11/global-variables-in-as3 which seems pretty handy and I'll definitely use it for other things such as level number and health and so on. However, I still can't use the .this function, so I'm unsure how to actually assign anything to the MovieClip stage, so that things can be added to it as children.

View 0 Replies

ActionScript 1/2 :: Reference Static Class Vars Via A String?

Feb 5, 2010

I am trying to set the value of some static vars but I need to reference the class with a string rather than a proper constructor. In AS3 I can do this with:

var ref:Class = getDefinitionByName(classDefinitionAsString) as Class;
ref[varNameAsString] = newValue;
 
I can't find an equivelant approach that will work in AS2 though. I have tried:

var ref:Object = new [classDefinitionAsString];
ref[varNameAsString] = newValue;

This seems to just create an Object and as the vars that I am trying to access are static I don't really want to be using 'new' I just want to reference the vars.

View 1 Replies

ActionScript 3.0 :: Instantiating Class Once Should Make Its Vars Static?

Jan 27, 2010

If I only instantiate a class once should I make its vars static? I understand how this is of benefit if I make multiple classes, clearly you use less memory as it creates a reference to the same place for each class. Are there any other benefits for creating static vars or functions ?

For example I have my class 'MainMenu' which I create once (might even be my document class). In it I create a
Code:
private var someHolderForStuff:Sprite = new Sprite();

Should I rather create
Code:
private static var someHolderForStuff:Sprite = new Sprite();

View 2 Replies

ActionScript 3.0 :: Global Variables: Singleton Versus Static Vars?

May 29, 2009

pros and cons of either using a Singleton that enforces only one instantiation of itself, versus creating one common class with static vars which can be accessed by all other classes that import it?

In my testing, importing but never instantiating works fine. I can even change the value of one of the variables and then have another class see that changed value later on in the program.

If I *know* I will never actually create an instance of my Global class using the New command (but will instead just reference the variables using the class's name), then why should I need to make it a strict Singleton?

View 9 Replies

ActionScript 2.0 :: Deleting Vars Local To A Function In A Class?

Mar 2, 2007

Is there any advantage to deleting vars instantiated within public or private functions in a class, or are they removed from memory after the function has been invoked/run? The function below is completely arbitrary for example:

ActionScript Code:
private function someFunctionHere(_ar:Array):Void {
var _swf:String = _ar[0];

[Code].....

View 2 Replies

ActionScript 2.0 :: Delete Vars Local To A Function In A Class?

Mar 2, 2007

Is there any advantage to deleting vars instantiated within public or private functions in a class, or are they removed from memory after the function has been invoked/run? The function below is completely arbitrary for example:

Code:
private function someFunctionHere(_ar:Array):Void {
var _swf:String = _ar[0];
var _nm:String = _ar[1];

[Code]....

View 4 Replies

ActionScript 2.0 :: Using SetInterval With MovieClips - Instance Not Been Scoped

Dec 18, 2009

I have created a number of Movieclips as part of my Navbar such as About Us, Contact etc. I'm using setInterval to send them to a function that springs them open one after another using the tween class. The they are dynamically generated and positioned using the following code, however when I want to use them as buttons by using onRollOver or onRelease they act like I'm not scoping them correctly. In other words the cursor does not change into a hand when over them. This is a setInterval issue as if I have them open just using attachMovie, the scoping works just fine.

The actual code is as follows:
function aboutUs () {
var mcAboutUs:MovieClip = this.attachMovie("mcAboutUs", "aboutUs_mc", 20, {_x:197, _y:520});
var x_elasticTween:Tween = new Tween (aboutUs_mc,"_xscale",Elastic.easeOut,0,100,1,true );
var y_elasticTween:Tween = new Tween (aboutUs_mc,"_yscale",Elastic.easeOut,0,100,1,true );
clearInterval(_global.intervalID1);
} function setIntervals() {
_global.intervalID1 = setInterval(this, "aboutUs", 1000);

There are more in here, each going to its own function to attachMovie and Tween them. This all works fine.

setIntervals();
this.aboutUs_mc.onRelease = function() {
OnRelease is suppose to activate another function that generates the "About Us" page but nothing happens as if the instance is not been scoped.
page_aboutUs();
}

View 2 Replies

Flex :: What Keeps Locally Scoped Objects Alive When Listeners Are Registered

Jul 5, 2011

I see this type of apparent magic in all sorts of AS3 code, but here is a reduced example:

[Code]...

As indicated in the code comment, the loader variable should fall out of scope after the URLLoaderExample constructor. However... it still seems to be kept alive (not garbage collected) somewhere since the onComplete listener/handler is able to receive it cleanly. Where is the magic/hidden/global reference to loader that keeps it alive so that it can complete it's load operation, and then be handed to the onComplete listener/callback? Can this reference be seen somewhere?

To help with context... as a similar example, I know that the loader instance will have the onComplete listener registered. I also know I need to be careful to use removeEventListener at all times (?) to avoid potential memory leaks resulting from stranded listeners. What concerns me is that I don't understand where the magic loader reference is and whether (or when) I need to clean that up.

View 3 Replies

ActionScript 3.0 :: Error #2148: Only Local-with-filesystem And Trusted Local SWF Files May Access Local Resources

Jul 4, 2010

I'm trying to load a local xml file:

xmlLoader.load(new URLRequest("../xml/xmlData.xml"));

But I'm getting this security sandbox violation:

#2148: Only local-with-filesystem and trusted local SWF files may access local resources.

I don't get this error when I embed the XML file directly with the EMBED metadata tag.

View 3 Replies

ActionScript 3.0 :: Can't Accses "block" Movie Clip Which's Added From The Fla Files And Given An Instance Name As "block"

Dec 31, 2010

So i have an external as file which have a function. the function make the movie clip do something when it hit another object which i named "block."

but the external as file can't accses "block" movie clip which's added from the fla files and given an instance name as "block".

View 4 Replies

ActionScript 2.0 :: Variables "scoped" To The Main Timeline?

Jan 2, 2007

I am going through the tutorial in the Flash MX 2004 Bible, Chap 33 "Creating A Game in Flash" when on page 1000, the author states in a side note that "We don't use the var keyword here because we want the style variables to be scoped to the main timeline of the movie. In this way, we can access the styles from various functions throughout the game."I've noticed what I thought were two ways to declare variables:

1. "someVar:Type = someThing"
2. "var somVar:Type = someThing"

I never knew what the difference was between these two methods.

View 14 Replies

ActionScript 3.0 :: Private Static Properties With Public Static Getters/setters

Oct 22, 2009

how bad is this practice? I am having trouble getting to some stuff so i am taking the easy way out

Code:
private static var _interrupted:Boolean;
public static function setInterrupted(value:Boolean):void{
_interrupted = value;
}

View 1 Replies

ActionScript 2.0 :: Load Vars From A Text File Into A Load Vars Object?

May 19, 2005

i am trying to load vars from a text file into a load vars object.

var kitchentext = new LoadVars();
kitchentext.load('moccastext.txt');

Once in the object, i thought i could reference them like so

kitchentext.name
kitchentext.style

but i am having trouble doing this.

i have a textbox called displytext.

_root.displaytext.text = kitchentext.name;

doesnt work

View 3 Replies

ActionScript 3.0 :: Altering A Reference To A Static Var Alters The Static Var Itself?

Aug 25, 2009

Let's say you have the following situation:

1. Static var(an Array) stored in a class.
2. You create a variable reference to the static class in a separate class.
3. Splice some items from the reference variable in the separate class.
4. Trace the static class and the items have been removed from that too.
5. Verify several times.
6. Get confused.
7. Post on Kirupa.

View 3 Replies

ActionScript 3.0 :: Static Function Can't Find Non-static Functions

Jan 6, 2010

Ok, so I have a bit of a mess here (Which I'm probably not doing right anyway, which could be my problem...). I have a document class, I'll call it as Body.as, that creates an object from another class known as Headgear.as. There are also other objects created from other classes, or will be in the future. Now, amoung all this, Headgear.as and all of the other classes Body.as will use to make objects require the use of dragging functions (starting and stopping dragging). On stopping drags, position checks are then made to compare a particular hidden movieclip with the dragged MC.

To try and save myself some hassle (from making the same functions over and over to ensuring that when the objects are created I don't need to send a complete crapload of variables just to ensure the position checking function would work), I had the functions for the event listeners (Which are set-up on the draggable MCs in Headgear.as) just direct to functions in Body.as

[Code]...

View 6 Replies

Actionscript 3 :: Does Static Methods Need To Use Static Properties?

Dec 28, 2009

If I created a static method. say I decide to call on other methods within that static method. Do those methods I call on need to be static as well? what If I used some of the properties. Not to store data permanently, but just within that process. Do those properties need to be static ??

View 3 Replies

ActionScript 3.0 :: Static Classes And Static Methods?

Feb 21, 2007

Yesterday I found myself wondering, what is the difference between either having a class with methods that are all static, or simply giving your class the static attribute?

View 9 Replies

ActionScript 3.0 :: Static Class Needs A Non-static Function

Nov 22, 2009

Alright, so I have a class that is linked (via the linkage panel) to a scrollbox class. I'll paste the class here:[code]Ignoring the formatting, the commented out functions are the ones causing the issue. Adobe says that it's a static class and I can't use non-static functions. The way I wanted to use it was:

1. Call the page button generating function above.

2. In the main code in my program is this line:scrollbox.setClickFunction(historyContent.generate Page);So when the buttons that are supposed to be generated are clicked, the scrollbox class can call the History pages generatePage function and pass it which page to show. (I did this because there was a lot of text and a limit on how much would display, so small chunks sounded logical).

3. In the onClick function (which I haven't finished yet because the rest wont work), when you click one of the buttons it calls the set function. Its that simple.

View 4 Replies

Flash :: Execute An External .exe From A Local .swf Using A Local XML Socket Server (C#)

Jan 7, 2012

I'm developing a game add-on/plugin which replaces a built in feature of an online game. The game loads an .swf therefore, my solution also has to be an swf for it to work 'in-game'.

I would like to be able to have the user press a button in the custom .swf I am making - and this would open an external application (amongst other things). I.e. if there was a button that said Notepad, it would open Notepad.exe on the machine.

My initial thinking was that i could have a XML Socket server 'daemon' runnning (c#) , which i could connect to with flash - however, as both the swf and the daemon are local, flash complained and gave this error: "Error #2010: Local-with-filesystem SWF files are not permitted to use sockets."

The only way i know to fix this - is to change the security settings of flash - not very user friendly!

So! Any thoughts on how I could otherwise go about this? I was thinking a custom http server could do the trick (connected with URLRequest) although i'm not too sure.

View 1 Replies

ActionScript 2.0 :: Launching A Local Html File From Local Swf?

Jan 16, 2007

i am having a problem launching a local html file from my swf. i have a button called print that when clicked it is supposed to open the local html file and print out the content. this is the code i used on the button

on (release){
getURL("folder/folder/file.htm","_self");
}

[code].....

View 4 Replies

ActionScript 3.0 :: Static Methods - Error "1119: Access Of Possibly Undefined Property Instance Through A Reference With Static Type Class"

May 4, 2009

I'm kind off oblivious as to what I'm doing wrong here... I have two classes: - Alley - AlleyCat

[Code]...

View 8 Replies

Flash :: Adding A Folder On The Local Network To The List Of "local-trusted" Places

Jul 22, 2011

I have a SWF file located at the local network in the public shared folder that I do not control over trying to read the external file on the local network.

I am currently hitting instead an security violation

Error #2148: SWF file file://....mySWF.swf cannot access local resource file://...config.xml"

I've added the network path where SWF an XML file resides to "trusted locations" via Flash Player Global Settings.

The added network path is successfully displayed at the list of "trusted locations" within Global Settings Manager, but it does not look like Flash Player is able to really parse the local network path as a "trusted location"

FP 10.3.181.23, Win XP

View 1 Replies

Flash8 New Kid On The Block?

Apr 17, 2009

I maintain two web sites and am reasonably competent in Dreamweaver and Fireworks. Now to get into Flash.I want to produce a banner which shows a flag + Welcome in that language and have about 20 nations to cover. Can anyone please point me to a guide as to how to get this started?

View 1 Replies

Javascript :: Access An Local Image (not In App Workspace) From A Local HTML File (in App Workspace)

Mar 12, 2011

I have a HTML box and load a local html file from the project. In this HTML file I use jquery and I want to load an image from my user directory. I see the image from my user directory but jquery doesn't works. I get this error:

[Code]...

But if I load an image from the app workspace, everything works fine (I see the image and Jquery works). Is this a policy problem? The error says that is a "null object reference" problem, but this can't be true...

View 2 Replies

ActionScript 3.0 :: NavigateToUrl - IE8 Pop Up Block

Jun 30, 2010

I have a question: The following code, which works OK in Firefox and Safari, gets IE8 to throw a pop up block The simple code:

[Code]...

View 3 Replies

Actionscript :: HtmlLoader Block Ads?

Dec 14, 2010

I've got an AIR app that is loading mx:HTMLs. I would like to block the ads that show in them just like Adblock Plus for Firefox does (see http://adblockplus.org/en/). I subscribe to the Easylist USA filter.

var req:URLRequest = new URLRequest("http://www.google.com");
thisHtmlWindow.open();
thisHtmlWindow.htmlContent.htmlLoader.load(req);

I don't know where to begin to interrupt the HTML GET-ting process in actionscript. This is where I suspect I can add the HTTP filter. It'd be nice to subscribe to the filter and periodically download it/update it to make sure the major ad networks are blocked.

View 1 Replies

ActionScript 2.0 :: Use } Or }; At The End Of A Code Block?

Dec 14, 2006

Something I've always wondered, but never got round to asking is should I use...

Code:
}
... or...

Code:
};

... at the end of a code block? What's the difference as I've seen both used but no explanation as to why?

View 4 Replies

IDE :: Catch Block Not Working?

Oct 29, 2010

why my code not workinghere is my as code

package com_dp
{
import flash.net.URLLoader;

[code].....

View 1 Replies

How To Make A Layer Block Buttons Below It

Jun 8, 2009

ok i'll try and explain this best i can, on my site i have a menu that takes up the whole of the content area.. the plan is that when the user clicks the menu button within a content page the menu would appear over the top however with a slightly transparent background so you can still see the last visible content page in the layer underneath.. i've got this to work however the buttons within the content page are still active.. is there a way i can make the menu layer 'solid' so the content below is only visible but not accessible?

View 5 Replies







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