Skip to main content
Petro_O__Bochan
Inspiring
July 12, 2010
Question

this.callPrefix

  • July 12, 2010
  • 1 reply
  • 835 views

Hi, although this is an ActionScript "issue" but I'm curious whether the framework's namespacing variable this.callPrefix is going to work in AS3 with FMS4?

    This topic has been closed for replies.

    1 reply

    Participating Frequently
    July 13, 2010

    Did not get your question clearly so can you elaborate with say some example code snippet.

    My guess right now is , if it worked with previous version of FMS , it should work with FMS4.

    Petro_O__Bochan
    Inspiring
    July 13, 2010

    Try this:

    ASC file(s):

    main.asc:

    load('connect.asc');

    connect.asc:

    try { var dummy = FCConnect; } catch (e) {
    load('components/component.asc');
    FCConnect = function(name) {
      this.init(name);
    };
    FCConnect.prototype = new FCComponent('FCConnect', FCConnect);
    FCConnect.prototype.getTime = function(client) {
      client.call(this.callPrefix + 'setTime', null, String(new Date()));

      // client.call('setTime', null, String(new Date()));
    };
    }

    ----------------------

    AS2 Flash file regardless of Flash Player version:

    import mx.utils.Delegate;

    var nc:NetConnection = new NetConnection();
    nc.FCConnect = new Object();
    nc.FCConnect['_DEFAULT_'] = this;
    nc.onStatus = Delegate.create(this, onStatus);

    function onStatus(event:Object):Void {
    nc.call('FCConnect._DEFAULT_.getTime', null);
    }

    function setTime(event:Date):Void {
    trace(event); // triggers allright by server-side component
    }

    nc.connect('rtmp://yourdomain.com/prefix');

    ---------------------------------

    AS3 Flash script file regardless if its FP9 or 10:

    package {
    import flash.display.Sprite;
    import flash.events.NetStatusEvent;
    import flash.net.NetConnection;

    public class Prefix extends Sprite {
      private var nc:NetConnection;

      public function Prefix() {
       nc = new NetConnection();
       nc.client = this;
       nc.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
       nc.connect('rtmp://yourdomain.com/prefix');
      }

      private function onStatus(event:NetStatusEvent):void {
       nc.call('FCConnect._DEFAULT_.getTime', null);
      }

      public function setTime(event:String):void {
       trace(event); // doesn't get triggerred
      }
    }
    }

    ---------------------------

    The problem for AS3 is that when the server-side component does the remote call with this.callPrefix, the client-side "component" function isn't triggered. If you remove the this.callPrefix it works fine but you loose component namespacing. No matter you play around with the "client" property of the NetConnection object; no matter you make the NetConnection object dynamic or make the class dynamic, provided you use the this.callPrefix, it doesn't work. This behaviour pertains to all editions of FC/MS, since gFrameworkFC component invocation is the same, but is inherent to AS3 only, cause such namespacing works fine for AS1-2. You could of course have a workaround for this by using SharedObjects, but it should work natively. In other words:

    this.callPrefix = this.derivedTypeName + "/" + this.name + "/"; // component.asc

    doesn't work for AS3.

    If source needed - http://www.pbochan.com/misc/prefix.rar

    Participating Frequently
    July 13, 2010

    I suppose like you said its an AS issue or more of FP issue. I think its known issue with FP9 and above - i did some googling and found it so. I got one link which might be helpful to you (if you already have not got to it) - http://jessewarden.com/2006/07/porting-flashcom-applications-to-actionscript-3.html