title: Trying to connect to AMFPHP - NetConnection.connect() returns TypeError: Error #1009
body: <p><strong>UPDATE:</strong> Now I've moved the AMFConnection var declaration to outside the functions in Main, and commented out some trace() commands, and now it gives new errors:</p>
  
  <pre><code>Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.BadVersion
  at AMFConnection/init()[/Users/Jan/Downloads/amfphp1/AMFConnection.as:32]
  at AMFConnection()[/Users/Jan/Downloads/amfphp1/AMFConnection.as:23]
  at Main/testConnection()[/Users/Jan/Downloads/amfphp1/Main.as:14]
  at Main()[/Users/Jan/Downloads/amfphp1/Main.as:10]
  </code></pre>
  
  <p>All of these essentially point to AMFConnection's NetConnection initialisation: <code>_netConnection = new NetConnection();</code> (where _netConnection is declared at the beginning of the class)</p>
  
  <hr>
  
  <p>I'm trying to connect to AMFPHP on a server (with Flash AS3), and the swf borks when it reaches the .connect() stage. To make things easier (?) and more reusable (?), I've put all the NetConnection mechanics into a separate class, AMFConnection, which I call from the Main document class like this (details changed):</p>
  
  <pre><code>public function testConnection(e:*=null):void {
  var conn:AMFConnection = new AMFConnection();
  conn.table = "some_table";
  conn.selections = "*";
  conn.conditionals = "WHERE something = 'something'";
  conn.service = "QueryAMF";
  conn.method = "makeQuery";
  conn.displayText = txt;
  conn.gogogo("http://www.someplace.com/Amfphp");
  }
  </code></pre>
  
  <p>AMFConnection actually starts the connection and calls the AMFPHP service with the function gogogo(), and here's where the connect() NetConnection function just won't work. Here's the main section of the AMFConncection class</p>
  
  <pre><code>private var _netConnection:NetConnection;
  private var _responder:Responder;
  
  function AMFConnection()
  {
  init();
  }
  
  private function init(e:* = null)
  {
  _netConnection = new NetConnection();
  _responder = new Responder(uponResult);
  }
  
  public function gogogo(url:String):void {
  trace(url);
  _netConnection.connect(url);
  _netConnection.call(String(service+"/"+method), new Responder(onResult, null), table, selections, conditionals);
  }
  </code></pre>
  
  <p>A quick debug session reveals the below errors:</p>
  
  <pre><code>TypeError: Error #1009: Cannot access a property or method of a null object reference.
  at AMFConnection/gogogo()[AMFConnection.as:44]
  at Main/testConnection()[Main.as:20]
  at Main()[Main.as:8]
  </code></pre>
  
  <p>Where: <code>Main.as:20 = conn.gogogo(...)</code>, and <code>AMFConnection.as:44 = _netConnection.connect(url)</code>;</p>
  
  <p>It also fails to display the stage, instead showing the loading dots. Now, eventually I'm going to move this application to the same server as the AMFPHP service, but even when I try it there with a relative url, instead of an absolute one, it still breaks down at connect(). I've tried changing the publish settings from local only to network only, to no avail.</p>
  
  <p>Any clues? Know a better way to connect to AMFPHP locally? </p>
  
  <p>Cheers in advance!
  JB</p>
  
  <p>P.S. Post updated, see top of page.</p>