[xray] Minimal connector-only code

Karina Steffens karina at neo-archaic.net
Tue Feb 7 10:24:23 EST 2006


Hey J, 
 
Take a couple of days off and they're batting at you from all corners ;)
 
You're welcome, as always! You probably don't remember, but I actually sent
you this script a couple of months ago ;p
 
Personally, I like both singletons and static methods. The Tooltip class in
Xray, for example, is all Static interface. I suppose it could have been a
singleton as well, but Static seemed to work better. Then again, I also have
a project-specific sharedObject wrapper class which is referenced from
different parts of a huge application and saves/tracks its state. It caused
me a lot of headache until I turned it into a singleton.
 
I made a few extra mods to the XrayConnect class - it now uses
"XrayConnector.swf" by default but this can be changed by passing a new
parameter to the getInstance method.
Also, getInstance() can now be called without any parameters at all, and
_level0 will be used by default.
 
Because I noticed it takes the external connector a few milliseconds to load
(as should have been obvious, if you're not a total dummass like me), I also
added a public static var Connected, which can be used to quickly check if
the external connector has loaded.
 
So, anyway, here is the new and improved class. I hope I haven't bloated it
too much!:
 
----------------------------------------------------------------------------
----------------------------
/**
 * Used to initialise the Xray Connector Only Package
 * as a Singleton called by other classes.
 * The entry point is the static getInstance() method, with optional
parameters.
 * 
 * @author Chris Allen chris at cnmpro.com
 * @author John Grden johng at acmewebworks.com
 * @author Karina Steffens karina at neo-archaic.net
 */
 
import com.blitzagency.xray.util.*;
 
class com.blitzagency.xray.util.XrayConnect
{
 
 private static var instance:XrayConnect;
 //default connector swf
 private var connectorPath:String = "XrayConnector.swf";
 /**
  * A static test property which can be used to check if Xray is connected.
 */ 
 public static var Connected:Boolean = false;
 
 function XrayConnect(containerClip:MovieClip, showFPS:Boolean,
newConnectorPath:String)
 {
  connectorPath = (newConnectorPath != undefined) ? newConnectorPath :
connectorPath;
  containerClip = (containerClip != undefined) ? containerClip : _level0;
  init(containerClip, showFPS, newConnectorPath);
 }
 
 /**
  * Main entry point into the connector.
  * All the parameters are optional. Default values that will be used
instead are:
  * containerClip: _level0
  * showFPS: null/false
  * newConnectorPath: XrayConnector.swf
  */
 static public function getInstance(containerClip:MovieClip,
showFPS:Boolean, newConnectorPath:String):XrayConnect{
  if (XrayConnect.instance == undefined){
     XrayConnect.instance = new XrayConnect(containerClip, showFPS,
newConnectorPath);
   }
   return  XrayConnect.instance;   
 }
 
 /**
  * The method to run when the Connector.adminToolLoadComplete event is
triggered.
  * Connector.trace, Connector.tt, Connector.tf are setup here to pass
arguments to the admintool
  */
 public function LoadComplete()
    {
  var ttExists:Boolean = _global.tt ? true : false;
  var tfExists:Boolean = _global.tf ? true : false;
  var icExists:Boolean = _global.com.blitzagency.xray.Xray.initConnections ?
true : false;
  //you can either call AdminTool trace(), tt() and tf() using _global
  //or by using the Static methods of the Connector class
  //_global.tt("Xray methods available? - ", "\n_global.tt? ", ttExists,
"\n_global.tf?", tfExists);
  //TRACE(Flashout.DEBUG + "ttExists :: " + ttExists);
  if (ttExists && tfExists){
   _global.tt("Xray Connector Loaded")
   XrayConnect.Connected = true;
  }  
 }
 
 private function init(containerClip:MovieClip, showFPS:Boolean):Void {
  XrayLoader.addEventListener("LoadComplete", this);
     XrayLoader.loadConnector(connectorPath, containerClip, showFPS);
 }
}
 
----------------------------------------------------------------------------
----------------------------
 
 
 


  _____  

From: John Grden [mailto:neoriley at gmail.com] 
Sent: 07 February 2006 13:24
To: xray at osflash.org
Subject: Re: [xray] Minimal connector-only code


Hey all, I finally caught up with this thread ;)

Karina, thanks for doing this!  really appreciate it, as always

_root :  I would suggest not using _root, but _level0 to be more specific.
_root, is a little more vague in that _root can be affected by levels and or
_lockroot property. 

Singleton : I myself, don't have a problem with using a singleton - in fact,
I use em' all the time depending on the need.  Usually, in a situation where
scope and static meet.  In fact, I'd really like to swith the Xray.xray
class to singleton since it works with a component on stage.  I have to do
some crapy workarounds because of inspectable properties not being available
to the static methods.

One fix I use in this situation, that seems very handy and still oopish is
to give an "_instance" property: 

class com.blitzagenyc.xray.myclass extends MovieClip
{
   public static var _instance:MovieClip;

   // constructor
   function myclass()
   {
      _instance = this;
   }
}

//then, when I need to get to that instance 
import com.blitzagenyc.xray.myclass;
var value = myclass._instance.propertyName;
myclass._instance.methodName();

Anyway, the singleton approach is a fine way to do it IMHO, but I understand
*why* Chris did it staticly 


On 2/6/06, Karina Steffens <karina at neo-archaic.net> wrote: 

> Thanks! It worked first time :-).

Excellent! :)

>
> > method from anywhere in your application. The method needs to be
> > passed a movie clip reference to load the connector in.
>
> I passed in "_root". Is that the best option normally?

Yes, _root is as good a place as any to load the connector, I think.
Anywhere where you can create a new movie clip would work just as well. 

>
> > Looking at it again, it's probably the wrong place for the
> connector
> > name, if that can be changed. It might be better to just give the
> > connector a generic name (" XrayConnector.swf" perhaps?) ...
>
> I think that is a good idea and I made that change, renaming
> the connector swf to match.

I think it makes sense to do so, especially if you're using this with 
multiple projects. The original connector can keep it's own name and
versioning, and copies inside projects can be given the generic name.
Any objections to this from John & Allen?

Karina


_______________________________________________ 
xray mailing list
xray at osflash.org
http://osflash.org/mailman/listinfo/xray_osflash.org





-- 
John Grden - Blitz 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/xray_osflash.org/attachments/20060207/238b9d54/attachment.htm


More information about the xray mailing list