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


Similar Posts:


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 A Class Failing, But DocumentClass Can Make It Work?

Mar 17, 2011

I'm having this problem: I have an external fla (Dawn.as) and I want to instantiate the class from the external file into the main swf timeline, but when I try doing that I get an error:

ActionScript Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Code::Chapter/initialise()

[code].....

View 5 Replies

ActionScript 2.0 :: Instantiating Character Class Inside Of Game Class

Feb 18, 2007

I am having a problem instantiating a Character class inside of a game class.I am working on converting URL...l these tutorials to A.S. 2.0.[code]

View 2 Replies

Actionscript 3 :: Make Static Method Act Over Object Of Its Class That Is Already On Stage

May 13, 2011

Is there a way to make an static method act over an object of its class that is already on the stage, without using the keyword "this"? I mean, like "generic object of this class: do what I'm telling you to do, wathever your instance name".My goal is to create an method that get called by any object of this class, based on the changing on the value of an external variable, but since I cannot use the "this" keyword to reffer to each instance, I could not figure out a solution.

View 1 Replies

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

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

Flash :: Instantiating A AMF PHP Class Not Working

Jul 9, 2010

I am trying to use AMF PHP to pass variables to a flash file, thus far I cannot see anything wrong with my code, but I have very little experience with creating classes, so here it goes, here is my code,

index.php:

<?php
include "amfphp/services/flashMe.php";
$session = true;

[Code].....

Flash is looking for the flashMe class and the push method within that class, but I keep getting null variables in my flash file when I run it

View 3 Replies

ActionScript 3.0 :: Instantiating Moviecilp From A Different Class?

Jan 28, 2010

My Class B imports Class A.Class A is associated to an FLA. This FLA has a moviclip (MC) in its library.Now I need to dynamically instantiate that movieclip MC from Class B. How can I do that??

View 9 Replies

ActionScript 3.0 :: Instantiating A Class (mc) At Runtime?

Nov 16, 2010

Code:
var myOnStageClip:MovieClip = this.fileInstanceMC;
var myLinkage:Class = Class(getDefinitionByName(getQualifiedClassName(myOnStageClip)));

[code].....

View 5 Replies

ActionScript 3.0 :: Using Document Class Vs Instantiating From Timeline

Dec 30, 2008

When I set the following class as my document class it works (draws a rectangle) but when I don't set it as my document class and instead instantiate it using var myRec:simple_shape = new simple_shape(); in first frame of my timeline nothing happens no rectangle and no error either). why and how I can get it to work without setting it as my document class?

[Code]...

View 6 Replies

ActionScript 3.0 :: Instantiating A Custom Class Through A String?

Oct 28, 2009

I asked yesterday how to call a function from an XML file, and I figured out how to make that work using the string-to-function call.so in my XML file I have <ITEM CALLBACK="ContactsList">View All</ITEM>, and my TextMenu class parses the XML file and creates my navigatable text menu instance. When enterMenu():String is called, it looks to see if the CALLBACK attribute has a value, and if so it returns it as a String.so..

var callbackFnc:String = textMenu.enterMenu();
if(callbackFnc != null)
{

[code].....

View 2 Replies

Actionscript 3 :: Instantiating Document Class Of Loaded SWF?

May 3, 2010

I am loading one swf into another using the Loader class, but when the child swf finishes loading and is added to the display list, its Document Class is not instantiated. I have a few trace statements that should execute when the object is created, but nothing is happening when loaded into the parent SWF. When I compile the child SWF on its own, the Document Class runs as expected.

So I'm wondering... how do I associate a child SWF's Document Class with Loader.content?

[Code]...

View 3 Replies

Flash - Loading SWF Without Instantiating Document Class?

Sep 26, 2011

Is there a way I can load a swf file but not automatically instantiate it's DocumentClass? Instead I want to do something like the following:
protected function mainLoaded(e:Event = null):void {
trace('mainLoaded');
var main:* = this.mainLoad.createClassByName('Main');
trace(main);
}
Where mainLoad is an instance of CasaLib's SwfLoad and createClassByName is the equivalent to
loaderInfo.applicationDomain.getDefinition();
The thing is that when my swf finishes loading I can see it is created, because of some trace calls, although its obviously not added to the display list.

View 1 Replies

ActionScript 3.0 :: Checking If Class Is A Subclass Of Another One Without Instantiating?

Jan 14, 2009

Here is the code:

ActionScript Code:
private class someFunction(classRef:Class):void
{
try
{
var instance:Object = new classRef();

[Code]...

Can I perform the check without instantiating?

View 1 Replies

ActionScript 3.0 :: Instantiating Class From External Function?

Nov 11, 2010

I've got a confusing situation which wont seem to fix itself basically I have my main class, my iContent class (which will hold each page and have functions for all pages), and my individual pages.

The homepage is instantiated by calling the iContentClass.goHome method in the main document class. The home page contains a button to go on to the next page. This button references the goColourBrowserPage function within the iContentClass, which removes the child (being the home page) and attempts to add a child (colourBrowserPage).

For some reason this doesnt work! It doesnt seem to add the child and wont let me remove the child of the home page! I've been sitting here for 3 hours trying to work it but to no avail!

[Code]...

View 1 Replies

ActionScript 3.0 :: Class.CONSTANT As Index When Instantiating Array?

Aug 3, 2010

Is there a way to declare and instantiate an array using constants as indexes? I want to do something like:

public var arr:Array = new Array([ CONSTANT_A : "helloWorld", CONSTANT_B : "helloGoodbye" ]);

In php one could do:

$arr = array(CONSTANT_A => "foo", CONSTANT_B => "bar");

View 9 Replies

ActionScript 3.0 :: Re-instantiating A Page Class In Original State ?

Nov 29, 2010

I'm making an app with pages set out as classes which extend the MovieClip class.

What I've got are back buttons and different pages which go to the same page, however... If I end up going out of a page and back into a page (specifically one with drawn squares and dynamic text boxes called from a web service), it seems to have kept all of the original information.

So far I've tried killing all of the children with a while loop targeting the index and also using weak event listeners - neither is working!

View 2 Replies

ActionScript 3.0 :: Navigating Through Timeline Of A MovieClip Class After Instantiating?

Jun 8, 2010

I have a MovieClip symbol that has 2 frames (for now). Depending on how it was initilialized, I want it to gotoAndStop at either frame or 2.Inside my class definition (Animal.as), I have written this as my constructor:

var type:String;
public function Animal(t:String = "") {
type = t;

[code]....

View 2 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

Actionscript 3 :: Access Properties And Methods Of A Class Without Extending Or Instantiating?

Jan 9, 2012

Let's say I have a defined ClassA. ClassB extends ClassA and there's a Movie Clip instance on the stage linked to ClassB. How would ClassC access the properties and methods of ClassB without extending ClassB or creating a new instance of ClassB? The way I'm currently doing it is by referencing the stage instance linked to ClassB and then using the dot syntax to access ClassB instance variables, and this works only if the the accessed variables are public or internal, depending on what package ClassC is part of. I would like to know if there's a better, cleaner way to accomplish this.

[Code]....

View 2 Replies

ActionScript 3.0 :: Error 1009, Instantiating A Class That Extends A Sprite?

Apr 25, 2009

've tried calling constructor class from my main.fla, and it just doesn't work. The error when I try to instantiate the constructor is that it needs an argument... and since the class extends a Sprite.

PHP Code:
public functionportGal():void {
this._images = new Array();

[code].....

View 3 Replies

ActionScript 2.0 :: Instantiating Multidimensional Array Of Movie Clips From Inside Of A Class

Dec 30, 2007

I am trying to set up a script that will generate a matrix repeating the same symbol X by Y times. For example, b(3,2); should generate...

OOO
OOO

...and after many days of being tested by this problem I have narrowed the location of my problem down to what can be seen up in the following.

Code:
for (a=0; a<4; a++){
for (b=0; b<4; b++){
var z:Number = ((a*4)+b);
_root.attachMovie("Light", ("L" + z), _root.getNextHightestDepth(), {_x:(a*45), _y:(b*45)});
}
}

For some reason, that loop will only attach one copy of my "Light" movie. I cannot seem to figure out why more are not added. I am putting that code on the first frame of my movie. There is nothing else in my project yet.

I have compared my array to [URL]

View 1 Replies

ActionScript 3.0 :: Flash - Document Class And Instantiating Linkage / Exported Library Items?

Aug 19, 2010

I have a symbol named picHolder. In symbol properties under linkage, I chose "Export for ActionScript" and "Export in frame 1" and gave it a class name of picHolder.Normally, to instantiate a new instance, I'd say:

Code:
var tempPic:picHolder = new picHolder();
and I'd go about my way.

[code].....

View 1 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

ActionScript 3.0 :: Sharing Vars Between Document Class And An Imported Class?

Jan 27, 2009

I've been sorting through the XML docs and i've bumped my head into a bit of a question. So, to preface, I have been able to load the XML successfully, but I want to be able to use my own XML loader class to load the XML and then be able to reference it from the document class. Also, I'd like to be able to send a file path to the loader class when I call it.

The document class:

ActionScript Code:
package rg.sites{
// flash classes

[code]....

View 8 Replies

Actionscript 3 :: Big Performance Difference Between Using Class With Static Functions Vs Instantiated Class?

Mar 22, 2012

I'm wondering if anyone has experience with if there is a big difference in performance in ActionScript 3 between keeping a class with only public static functions, and utilizing those functions often (as in a frame event at 30fps), and in turning the class into a "normal" class of which I instead make an instance and call the functions via the instance instead.

View 1 Replies

ActionScript 3.0 :: Accessing A Class's Static Functions From A Variable Of Type Class?

Feb 19, 2010

I realize this is kind of an odd issue, but I am wondering if there's any way to get Flash to allow me to access a class's static functions using a class variable that points to the class. Example:I create a class called FooClass that has a static function named fooI then create a variable of type Class that points to it

Code:
var class:Class = Class(getDefinitionByName("FooClass"));
However, when I try to call foo() using the variable, it errors saying the function

[code].....

View 6 Replies

Actionscript 3 :: Accessing Functions/Vars From Outside Of Class?

May 29, 2010

how can i call public functions or vars of a sprite class from another class (or frame script)? i keep getting 1061: Call to a possibly undefined method getSide through a reference with static type flash.display:Sprite.

//Framescript
var a:Sprite = new customRect();
addChild(a);

[Code]....

View 2 Replies







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