A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Quick class question

  1. #1
    Media Developer CJElven's Avatar
    Join Date
    Jan 2002
    Location
    San Antonio, TX
    Posts
    298

    Quick class question

    When writing an external class, is there a way to ALWAYS refer to the class? The circumstances that I'm referring to are when you use something like MovieClipLoader, or similar. Right now, for MovieClipLoader, to refer to the class that I'm writing the Listener in, I have to climb the various layers, and then back to the class I'm in through an embedded classRef tag that I inserted in the root movie while setting my class. So, it ends up looking like this:
    Code:
    myListener.onLoadInit = function (mc:MovieClip) {
    	var cRef = mc._parent._parent.classRef;
    	cRef.myImagesLoaded++;
    	if (cRef.myImagesLoaded == cRef.myTarget.numImages) {
    		cRef.placeImages ();
    		if (!myTarget.access508) {
    			mySound.start ();
    		}
    	}
    };
    Is there an easier or more sure way of referring to my calling class? Or do I always have to hunt for which layer is correct, and then reference that layer?

    Thanks for any help.
    Dragontech Media
    Magic.Fire.Content

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    As a cheap hack, you assign a reference to the class as a dynamic property prior to running loadClip().
    PHP Code:
    mc.boss someClassInstance;

    //then within onLoadInit
    var cRef mc.boss

    The problem, myListener should already have scope to classRef and shouldn't need to pick through an mc to find its parent.

    If you declared MCL in the same or lower scope as your custom class instance, you should be able to make a blind reference to it.

    PHP Code:
    myCustomClassInstance = new MyCustomClass();

    myMCL_listener = new Object();
    myMCL_listener.onLoadInit = function(mc){
      if(
    myCustomClassInstance.myImagesLoaded == myCustomClassInstance.myTarget.numImages){
    //
    }


  3. #3
    Media Developer CJElven's Avatar
    Join Date
    Jan 2002
    Location
    San Antonio, TX
    Posts
    298
    I would have thought that it would have a reference as well, but what it seems to do is either A) Spit out a compiler error (CS3) while stating that no such property exists, or B) It compiles normally but doesn't do anything. Please note that this is when the class is in an external .AS file. I haven't actually run this inside a flash file for reference purposes, but as this class is intended to control a LOT of similar pages, individual pages just don't work for me.

    I'll try just assigning the reference to the movie I'm loading into. Hopefully it doesn't wipe out the reference when it loads the external SWF in, though. But, it's a start. Thanks!
    Dragontech Media
    Magic.Fire.Content

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center