AS3: static vars and on-stage MC's

hi,
my basic problem is as follows:
i have one swf which loads another one. both of them have
document class.
i want to access a variable of the main swf's class from the
inner swf's
class, so i turned that var into static. it works fine, as
long as i don't
access MC's on the main swf's stage from its class. i've
tried to solve it
using the 'ApplicationDomain' but it still fails.
for testing purposes i've made 2 swf's - 'main.swf' and
'inner.swf', where
on the main's stage i've placed a button, with instance name
'myBtn'.
this is the main's class:
package {
import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.system.*;
import flash.events.*;
public class MainClass extends MovieClip {
private static var myStatic:String = "abc";
private var ldLoader:Loader;
public function MainClass(){
loaderInfo.addEventListener(Event.INIT, myOnInit);
private function myOnInit(eEvent){
ldLoader = new Loader();
var urlRequest = new URLRequest("inner.swf");
var context:LoaderContext = new LoaderContext (false,
ApplicationDomain.currentDomain);
ldLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
completeHandler);
ldLoader.load(urlRequest, context);
this.myBtn.addEventListener(MouseEvent.MOUSE_UP,btnUp);
private function btnUp(evt){
trace("btn up");
private function completeHandler(evt){
var inner = this.addChild(evt.target.content);
inner.myOnInit();
static function get staticVar():String{
return myStatic;
this is the inner's class:
package {
import flash.display.MovieClip;
public class InnerClass extends MovieClip{
public function InnerClass(){}
public function myOnInit(){
trace(MainClass.staticVar);
when i compile 'inner' i get the following error:
1119: Access of possibly undefined property myBtn through a
reference with
static type MainClass.
the only way to avoid this error is to comment the last line
of the
'myOnInit' function in the main class, however then there's
no access to the
main's MC's.
any solution?
thanks in advance,
eRez
www.allofme.com

Hi,
can you give us a bit of code ... that will help. And did you
declare your movieClip before (and outside of) the constructor?
Like this i mean:
class RandImg{
private var mcDefault:MovieClip; // --> here it is ..
mcDefault
public function RandImg(){ // --> cunstructor
trace("mcDefault path = " + mcDefault);
If mcDefault is not declare before and outside your
constructor, its impossible for your class to access it. Of course
you are probably aware of that .. but im trying to figure out what
can be the problem .. just guessing.
So please give us some code and we will try to help!

Similar Messages

  • Ensuring a static var stays updated

    Sorry for spamming the boards but I have another question...
    I want to get the index of the image currently in the center of the carousel and then I want to use this index number in other classes but it has to stay updated each time. I successfully managed to get the index of the image that is currently being clicked on (this image will then be moved to the center of the carousel so as long as one always clicks on an image at the start, my method will work ) but I dont know how to allow other classes to access this. I tried saving it as a static var and then trying to access it by using the following:
    private var coverIndex : int = CoverFlow.selectedCoverIndex;
    But I receive the error msg that selectedCoverIndex is not available to static class CoverFlow or something of that sort. This is what my CoverFlow code looks like (i.e. where I determine which image I want to position in the center):
    public class CoverFlow extends Sprite {
      public var covers : Vector.<DisplayObject>;
      private var cover : DisplayObject;
      private var coverIndex : int;
      private static var selectedCoverIndex : int; // Create a static coverIndex so I can easily use this data for external classes
      private function show(id : uint) : void // e : Event
       for (var i : Number = 0;i < covers.length; i++)
        cover = covers[i];
        // Tried putting if i == id as last statment to stop website coming up automatically but it still does since it then loops through again.
        if (i < id)
         setChildIndex(cover, i);
         TweenLite.to(cover, tweenDuration, {x: (id - i + 1) * -coverDistance, z: coverZ, rotationY: -coverRotationY, ease:easing });
        } else if (i > id)
         setChildIndex(cover, covers.length - 1 - i);
         TweenLite.to(cover, tweenDuration, {x: ((i - id + 1) * coverDistance), z: coverZ, rotationY: coverRotationY, ease:easing });
        } else if(i == id)
         setChildIndex(cover, covers.length - 1);
         TweenLite.to(cover, tweenDuration, {x: 0, z: selectedCoverZ, rotationY: 0, ease:easing });
      //____________________________________________________________________________Mouse functions on CoverFlow
      private function onClick(event : MouseEvent) : void
       // Always display product clicked on as center image
       cover = event.target as DisplayObject;
       coverIndex = covers.indexOf(cover);
       show(coverIndex); // Show the index number of the current displayed object
       selectedCoverIndex = getCoverIndex();
       trace("Index of Selected Cover : " + selectedCoverIndex);
      //____________________________________________________________________________Getters
      public function getCoverIndex() : int
       trace("Cover Index: " + coverIndex);
       return coverIndex;
    Hope you understand what I mean!!

    How stupid of me!!!
    I am not 100% sure it worked though... To start off it returns the current value (null) but then once I have clicked on one of the images, the coverIndex should change to the corresponding value. In the CoverFlow class it changes to a different value but I am not sure it does in the ProductSummaryLabel class (the latter is the class that imports the value from the CoverFlow class). The reason I believe this is that when in the CoverFlow I call the method setLabel from the ProductSummaryLabel class, which in turn is supposed to find the text in an array of texts which corresponds to the same index as that of the coverIndex, I receive athe following error message: "cannot reach a property or method with a null object reference". This seems to indicate that this variable in the ProductSummaryLabel class still contains the original null value and does not update itself.
    This is what my setLabel method in ProductSummaryLabel class looks like:
    public function setLabel() : void
       // Summary text depends on coverIndex, i.e. which image is currently in the center
       coverIndex = CoverFlow.selectedCoverIndex; // This should update itself each time I call the setLabel method!
       trace("Cover Index (Product Summary Label class setLabel()): " + coverIndex);
       var desiredSummaryString : String = uebersicht[coverIndex];
       trace("Product summary text: " + desiredSummaryString);
       productSummaryLabel.text = desiredSummaryString;
       productSummaryLabel.visible = true;
       trace("Step 10: Summary loaded");
    Below is the method in the CoverFlow class which gets the current coverIndex value and below that is the method which calls the setLabel method from the ProductSummaryLabel class (where pl is declared above as  private var pl : ProductSummaryLabel;).
    public function getCoverIndex() : int
       return coverIndex;
    private function onClick(event : MouseEvent) : void
       // Always display product clicked on as center image
       cover = event.target as DisplayObject;
       coverIndex = covers.indexOf(cover);
       show(coverIndex); // Show the index number of the current displayed object
       selectedCoverIndex = getCoverIndex();
       trace("Index of Selected Cover : " + selectedCoverIndex);
       // Ensures the text of prodctSummaryLabel is updated
       pl.setLabel();

  • Why global var can be initialized with a static method and not by other static global var declared after its usage

    Take this:
    class test
    static int i=j;
    static int j=10;
    this will give illegal forward reference ....
    but this will compile successfully ..
    class test
    static int i=test1();
    static test1()
    return 20;
    plz assume we have main method in both cases ..
    java would be loading all static members first and would be assigning default values .. and then will be running all the initializers from to bottom ..
    Why second case is a compile success and not first .. as in second also test1 method is declared after its usage ..
    Plz help.
    Thanks
    Abhishek Roshan

    Why second case is a compile success and not first .. as in second also test1 method is declared after its usage ..
    Because the implementors of Java intentionally chose to do it that way.
    There are TWO stages to the process: preparation (which occurs first) and initialization.
    See the Java Language Spec section 12.4.1 'When Initialization Occurs
    The intent is that a class or interface type has a set of initializers that put it in a consistent state, and that this state is the first state that is observed by other classes. The static initializers and class variable initializers are executed in textual order, and may not refer to class variables declared in the class whose declarations appear textually after the use, even though these class variables are in scope (§8.3.2.3). This restriction is designed to detect, at compile time, most circular or otherwise malformed initializations.
    Note the clause beginning 'may not refer to class variables'. And the authors give the reason for that restriction in the last sentence: detect circular initializations.
    Then if you check that referenced section 8.3.2.3 you will find this
    http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.2.3
    8.3.2.3. Restrictions on the use of Fields during Initialization
    The declaration of a member needs to appear textually before it is used only if the member is an instance (respectively static) field of a class or interface C and all of the following conditions hold:
      The usage occurs in an instance (respectively static) variable initializer of C or in an instance (respectively static) initializer of C.
      The usage is not on the left hand side of an assignment.
      The usage is via a simple name.
      C is the innermost class or interface enclosing the usage.
    When a method is used (your example 2) no circular initialization can occur because methods are not 'initialized'.

  • Communicate between SWF & Global static vars

    Sorry for my inglish...
    I’m having some problems on getting full communication between loaded SWFs. I'm totally stuck and my timing is running.
    Suppose the following scenario:
    Father-SWF has his own class and loads A-SWF and B-SWF. A and B SWF has his own class and package. To exchange values and run functions between SWF, I’m using a Global class with public static vars. Some of this vars are function, example:
    GLOBAL CLASS WITH STATIC VARS (com. with other class and package beetween SWF)
    package scripts
         public class GlobalAct
              public static var mainStage:Object;
              public static var myFuncGlobalA:Function;
              public static var myFuncGlobalB:Function;
    MAIN CLASS FATHER SWF
    package
         import flash.display.MovieClip;
         import scripts.GlobalAct;
         public class FatherClass extends
    MovieClip
              public function FatherClass():void
                   GlobalAct.mainStage
    = this;
                   GlobalAct.
    myFuncGlobal = myFunc;
              public function myFunc():void
                   //some wird stuff
    A_SWF CLASS
    package
    scripts
         import flash.display.MovieClip;
         import scripts.GlobalAct;
         public class Layout extends
    MovieClip
              private var someMc:MovieClip;
              public function Layout()
                    someMc
    = new MovieClip();
                    someMc. addEventListener(MouseEvent.CLICK,
    mouseFunc);
              public function mouseFunc (evt:MouseEvent):void
                   GlobalAct. myFuncGlobalA ();
    B_SWF CLASS
         Similar to A-SWF class but with other kind of functions…calling “GlobalAct.myFuncGlobalB();” for example.
    This works great, when I run Father-SWF, it load every SWF and functions run from SWF to SWF.
    The problem happens when I load Father-SWF in another SWF. There is a MAIN-SWF with his own set os class and a Global static vars Class.
    MAIN-SWF loads a SWF that will load Father-SWF into the MAIN-SWF.
    WORKING
    Father-SWF -> many SWF that could load other SWF
    NOT WORKING
    Main SWF -> SWF -> Father-SWF -> many SWF that could load other SWF
    When this happens none of the Global functions seems to work. The other Global vars seems OK, only function vars seems not to work.
    I only get the error: “TypeError: Error #1006: value is not a function. at scripts::Layout/ mouseFunc ()” when I try to click a button inside A-SWF.
    Does I lose my Global reference when loading the Father-SWF in another SWF?
    How can I make this bullet proof and generic for every situation?
    What’s the best oop practice to communicate between class and SWF on AS3?

    I figured it out.
    It's under the pop-up window. Select edit locations to select confirm.

  • Static blocks and inheritence

    public class SubClass extends SuperClass {
    static {
    System.out.println("Sub class being called");
    SuperClass.setS("TREX");
    public class SuperClass {
    protected static String s;
    static {
    System.out.println("Super being called ");
    static public setS(String t) { s= t; }
    static public String getS() { return s; }
    public static void main(String[] args) {
    System.out.println(SubClass.getS());
    The above prints
    "Super being called"
    null
    Why is "Sub class being called " not printed? It looks like
    the subclass static block never gets called.?

    hi
    may be i did not something catch right concerning static blocks and inheritence
    (jdk1.5x)
    please have a look at the following example.
    1. static block in subclass is only executed if the static vars are not defined final. why is this?
    2. why does not any subclass has its "own" hashtable colors?
    thanks
    hanspeter
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    import java.util.Hashtable;
    abstract class ParentStaticBlock  {
         static final Hashtable<Integer, String> colors = new Hashtable<Integer, String>();
         static void putColor(int colNumber, String colName) {
              colors.put(colNumber, colName );
         static String getColorNameFor(int colNumber) {
              return colors.get(colNumber);
    final class Child1StaticBlock extends ParentStaticBlock {
         public final static int ROT = 0x00000D;
         public final static int GELB = 0x00000E;
         static {
              System.out.println(" hello, here static block of Child1StaticBlock...");
              putColor(ROT, "ROT");
              putColor(GELB, "GELB");
    final class Child2StaticBlock extends ParentStaticBlock {
         public /*final*/ static int GRUEN = 0x00000A;
         public /*final*/ static int BLAU = 0x00000B;
         static {
              System.out.println(" hello, here static block of Child2StaticBlock...");
              putColor(GRUEN, "GR�N");
              putColor(BLAU, "BLAU");
    public class TestChildStaticBlock {
          * @param args
         public static void main(String[] args) {
              int colNo;
              String colBez;
              System.out.println("Static elements class Child1StaticBlock ->");
              colNo = Child1StaticBlock.GELB ;
              colBez = Child1StaticBlock.getColorNameFor(colNo);
              System.out.println("color yellow has number >" + colNo + "< and label >" + colBez + "<");
              System.out.println("");
              System.out.println("Static elements class Child2StaticBlock ->");
              colNo = Child2StaticBlock.BLAU ;
              colBez = Child2StaticBlock.getColorNameFor(colNo);
              System.out.println("color blue has number >" + colNo + "< and label >" + colBez + "<");
              System.out.println("");
              System.out.println("contents of hashtable(s) ->");
              System.out.println("ParentStaticBlock.colors:" + ParentStaticBlock.colors);
              System.out.println("Child1StaticBlock.colors:" + Child1StaticBlock.colors);
              System.out.println("Child2StaticBlock.colors:" + Child2StaticBlock.colors);

  • A basic question about static variables and methods

    What would be the effects if I declare lots of static variables and static methods in my class?
    Would my program run faster?
    Would the class take more memory spaces? (If so, how do I estimate an appropriate number of variabls and methods to be declared static?)
    Thank you @_@

    when you declare a static var the var isn't created for every instance of the class, it just "live" in the class
    when you declare a static method is the same, so if you have:
    class MyClass
    static int myMethod()
    //Method work
    you dont need to have a instance of the class to call myMethod, you can do such things like this.
    int value = Myclass.myMethod();
    if myMethod isn't static you can't do this.. so, if
    class MyClass
    int myMethod()
    //Method work
    you CAN'T call
    int value = MyClass.myMethod();
    instead, you have to write
    MyClass m;
    m = new MyClass();
    value = m.myMethod();

  • Static Var Memory???

    Hi,
    I have a doubt in the static variable memory storage. Suppose if
    i have declared a static var like:-
    static int i=10;
    Here the variable will occupy 32 bytes that is for int datatype or it will occupy only 2 for the value 10 ? Since it is static??
    Thanks,
    JavaCrazyLover

    Static has nothing to do with the size of variable.... it simply means that when in a class a variable/ method is declared as static all the objects of that class will not have individual copies of that variable/method and wlll instead refer to the same variable/method.....
    An integer always occcupies 4 bytes, ie. 32 bits. so if you store 10 in an integer the first 4 bits would be 1010 and the rest of the 28 bits would be filled with 0's regardless of whether it is static or not
    rgds,
    Juhi
    ps. one must always keep in mind that numbers are not stored in base 10...they are always stored in the form of their binary equivalent, i.e in base 2

  • Static var vs const var

    What's difference 
    public static var = 1000;
    public const var = 1000;
    Can I use public var {get;set;}
    public var {get;}
    puplic var {set;}

    A static field belongs to the type itself rather than to a specific object instance of that type:
    https://msdn.microsoft.com/en-us/library/98f28cdx.aspx.
    An object instance can access the static field but a static property or method cannot access an instance (non-static) field.
    The const keyword is used to declare a compile-time constant field that cannot be modified during runtime:
    https://msdn.microsoft.com/en-us/library/e6w8fe1b.aspx
    Please refer to the links above for more information.
    And please remember to close your threads by marking all helpful posts as answer and then start a new thread if you have a new question.

  • Help!! Static sound and Lock ups

    I recently updated to the newest Ipod Mini version software 1.4. and when i play the songs on my ipod i get static sounding sounds and when i look at the display timer, it looks like the ipod i slowing down.
    Also i'm getting lockups when i'm browsing.
    Ipod service told me to restore the ipod, and i have 3 times, 1 to the factory software version, and twice to the newer version. It didn't help, as i'm still hearing static sounds, and I've switched headphones and headphone jacks, and it still doesn't help.

    the exact same thing happened to me. Mine is an original mini which needless to say is out of warranty, so I need an answer that is not "replace the hardware". Is there a way to restore it to a previous version of the software?
    mini   Windows XP  
      Windows XP  

  • Hi i got a new airport express for christmas and i set it up as per instructions ,i even give a static ip and wpa2 security ..the problem is is when i come to want to use it it says its not on my network and a orange triangle shows .when i reboot it works

    hi i got a new airport express for christmas and i set it up as per instructions ,i even give a static ip and wpa2 security ..the problem is is when i come to want to use it it says its not on my network and a orange triangle shows .when i reboot it works..then if i leave it a while and try iy agian its disapeared of my network...i have a bt hub 3 ....any help please ..im not sure if itsa faulty express

    I really don't have an answer for that one. I guess that while trying to get things working correctly, I would use the most basic monitor I had which in your case would be the Eizon using the Thunderbolt port and adaptor.
    When you boot into Safe Mode the startup is quite slow, but you should get the Apple logo and then the spinning gear below it (release the SHIFT key when it appears.) Then after a little more time you should see a gray progress bar appear below the spinning gear. When that disappears the computer will startup to a login screen.

  • Adding a second Hard Drive for /var and /opt

    I need some help... I have an Ultra 60 with 1 36 Gig drive, Solaris 10 with Java DeskTop. I want to add a 9 Gig drive to extend /var and /opt. Below is the data on the disk (format). My question is: How do I set this disk up so the /var and the /opt can extend into the new drive and then mount the drive. I am NOT a guru on setting up HD's and have read the Solaris admin book part to help me along, I am very lost. When I installed Solaris 10 I gave the /var 15 megs. It seems Solaris 10 patch manager wants to install all the patches in /var/sadm/patch thus I am eating up the 15 megs fast. What I need to know is just how to set up the below drive... HELP!
    format> verify
    Primary label contents:
    Volume name = < >
    ascii name = <SUN9.0G cyl 4924 alt 2 hd 27 sec 133>
    pcyl = 4926
    ncyl = 4924
    acyl = 2
    nhead = 27
    nsect = 133
    Part Tag Flag Cylinders Size Blocks
    0 root wm 0 - 73 129.75MB (74/0/0) 265734
    1 swap wu 74 - 147 129.75MB (74/0/0) 265734
    2 backup wu 0 - 4923 8.43GB (4924/0/0) 17682084
    3 unassigned wm 0 0 (0/0/0) 0
    4 unassigned wm 0 0 (0/0/0) 0
    5 unassigned wm 0 0 (0/0/0) 0
    6 usr wm 148 - 4923 8.18GB (4776/0/0) 17150616
    7 unassigned wm 0 0 (0/0/0) 0

    Here's another idea: use Live Upgrade. I'll assume your "new" 9G disk is on /dev/dsk/c0t1d0. Use format to partition the disk with one partition, /dev/dsk/c0t1d0s0. Don't mount the new parititon. Use Live Upgrade lucreate to put the boot environment on the new partition:
    lucreate -c be1 -n be2 -m /:/dev/dsk/c0t1d0s0:ufs(You can probably come up with more useful names than "be1" and "be2"!)
    lucreate will copy over all your existing root, /usr/, /var to the new disk. This will take a while, but you can continue using your system while it runs (no need to be in single user mode.) When it's done, use luactivate to make the new boot environment active and boot it.
    This gives you a system with everything in one partition. If you want to stick with different partitions for the different systems, lucreate can do that too, see the man page and docs. I think it's more trouble than it's worth for a single-user/desktop type system.
    Once you're up on the new disk, you can look into repartitioning the old disk to get you a similar-size partition to use as a spare boot environment, and you can start using Live Upgrade for what it was designed for: letting you upgrade without taking the system down.

  • Bind vars and LOVs on same JSP -incompatible?

    I have managed to get a project working using bind variables, and another project working that has LOV. (Both using ADF,struts,JSP)
    However, when I try and use bind variables for one attribute and an LOV for a different attribute on the same JSP I get the error msg:
    No getter method available for property x for bean name org.apache.struts.taglib.html.BEAN
    at org.apache.struts.taglib.SelectTag.calculateMathcValues(SelectTag.java:327)
    Is it not possible to have bind vars and LOVs on the same page or have I just messed sthg up?(more likely...) Seems weird that I can get them working separately. Any help appreciated... not knowing Java I'm rather at my wits end...!

    Hi kian chye,
    unfortunately it is not possible to use the page item bind variable in shared components for more than one page.
    If you want to get it to work you have to use application item in the LOV (shared components).
    Then on change of the first selection (region) you should write the new selection (region) into the application item (maybe with a javascript code). Then the LOV of the city should work.
    For the javascript code see an example here:
    http://apex.oracle.com/pls/otn/f?p=31517:119
    Regards,
    Denise
    www.appsassociates.de

  • When should I use static variable and when should not? Java essential

    When should I use static variable and when should not? Java essential

    Static => same value for all instances of the class.
    Non-static => each instance can have its own value.
    Which you need in which circumstances is completely up to you.

  • How to Create a Unix Agent and data stage adapter

    Hi Gurus,
    I am new to this tool. We have installed trail version of tidal scheduler tool. Kindly let me know how to create a unix agent and data stage adapter using some screen shots. Also please let me know is it possible to create agents on trail version
    Thanks,
    Saravanan Viswanathan                  

    edburns wrote:
    Can someone please tell me how to create a Unix Group on Leopard and how to add myself to that group?
    Ed
    man dseditgroupshould help. Look particularly at the examples.

  • Static class and clustering

              I have a static class that I use to cache some values during a batch process. The
              batch process uses a JMS queue to parcel our identical units of work to MDBs.
              I want this to scale using a cluster with the same MDBs on multiple machines.
              Everything works fine except that I can't figure out how to tell my cache to clear
              itself out on every node between batch runs. Is there a pattern or solution to
              this problem?
              What I've tried is to create a stateless session bean method that clears my cache.
              At the begining of my batch job, (which is a stateless session bean call) I call
              this method on each server in the cluster by getting the remote interface for
              the stateless bean via the different URLs of the servers. However, the session
              bean method always executes on the one server where I make the call. It's as if
              WebLogic gives me back a local interface instead of the remote interface that
              I asked for.
              Any ideas would be appreciated.
              Colin
              

    ... static class and static method.I have never heard of a thing called "static class". Perhaps you mean a class with only static members?
    My design approach (which is bound to needs of the moment and seldom to library-development or future re-use, since both is harder than most developers realize) is to develop straight without caring too much about static or not. When a method is done, debugged and works well, it happens that other objects access this method as well.
    It may happen that I just want to use this single method and almost nothing else of the object. If that is the case, I can start looking if it's a Good Thing(tm) to make the method static, so no object creation is needed just for the one method. Sometimes it can be done, sometimes not.
    But that's just me and you'll find quite a lot of coders that'll advice you to decide what's static and what not before you start coding. And that's as good an advice as most others you can get.
    In the end it's your decision, so start fiddling around and see what fits best for you.
    -T-

Maybe you are looking for

  • Skype use in education is it possible on free lice...

    Hi, I wonder if any one here would be able to help/advise me or point me to the correct person for support? I work in a FE College - we would like out learners to use skype to complete one of their modules - the module to complete is to connect to an

  • I bought a apps in my phone which is not working

    Hi there I bought a apps today wich is not workin as it's says on iTunes And I paid for that £2.99 Plz I want to refund my money

  • JSP function

    Hi, I want to create a function in a jsp page and after I want to call this functin from another page. How can I do that? Thank you! Caroline

  • Error in activating my email

    after activating my blackberry on a particular network, i put in a new sim card in my phone, now each time i try to activate my email, it displays this message.. "your device encountered a problem with this enterprise server" pls how can i remedy thi

  • Pbm in server.XML

    i am using netbeans IDE and there i took the server.xml in tomcat4.0.6 under runtime as installed server.and i modified in tht server.xml according to my needs. But if i navigate in netbeans IDE and i navigate into tomcat there i went and i saw the t