Skip to main content
New Participant
August 17, 2013
Answered

TypeError: Error #1009: Cannot access a property or method of a null object reference

  • August 17, 2013
  • 1 reply
  • 1230 views

im working on a little project which involves me using php,flash and mysql together. basically im trying to input some data from flash into a database and be able to retrieve it back and show in flash. some how i seem to have run into to types of errors, this so called typeError and the ArgumentError which are really irritating me. maybe its because im up late as i dont seem to understand it. here are the errors:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

          at Main/onResult()

ArgumentError: Error #2173: Unable to read object in stream.  The class flex.messaging.io.ArrayCollection does not implement flash.utils.IExternalizable but is aliased to an externalizable class.

and here's the AS coding

package

{

          import flash.display.MovieClip;

          import flash.display.Sprite;

          import flash.events.MouseEvent;

          import flash.net.NetConnection;

          import flash.net.Responder;

          import flash.text.TextField;

          import com.demonsters.debugger.MonsterDebugger

          /**

           * ...

           * @7111211 DAR

           */

          public class Main extends MovieClip

          {

                    private var conn:NetConnection;

                    public var name1:TextField

                    public var name2:TextField;

                    public var name3:TextField;

                    public var name4:TextField;

                    public var rating1:TextField;

                    public var rating2:TextField;

                    public var rating3:TextField;

                    public var rating4:TextField;

                    public var comments1:TextField;

                    public var comments2:TextField;

                    public var comments3:TextField;

                    public var comments4:TextField;

                    public var inputName:TextField;

                    public var inputComment:TextField;

                    public var inputRating:TextField;

                    public var submitReviewBtn:Sprite;

                    public function Main()

                    {

                              MonsterDebugger.initialize(this);

                              trace ("document class running");

                              setupConnection();

                              setupInputArea();

                              getReviews();

                    }

                    private function setupInputArea()

                    {

                              submitReviewBtn.addEventListener(MouseEvent.CLICK, addNewReview);

                    }

                    private function addNewReview(e:MouseEvent):void

                    {

                              //Add review to database

                              var resAddReview:Responder = new Responder(onAddReviewSuccess, onAddReviewFail);

                              conn.call("yomo_films.addReview", resAddReview,  inputName, inputRating, inputComment);

                              gotoAndStop(5);

                    }

                    private function addUserReview():void

                    {

                              var resAddReview:Responder = new Responder(onAddReviewSuccess, onAddReviewFail);

                              conn.call("yomo_films.addReview", resAddReview, "Amanda", 5 , "Really good movie");

                    }

                    private function onAddReviewFail(o:Object):void

                    {

                    }

                    private function onAddReviewSuccess(o:Object):void

                    {

                              //Refresh all Reviews

                              getReviews();

                    }

                    private function getReviews():void

                    {

                              //Create a responder object

                              var res:Responder = new Responder(onResult, onFail);

                              //Run a call to our service

                              conn.call("yomo_films.getReviews", res);

                    }

                    private function onResult(o:Object):void

                    {

                              trace("Success");

                              MonsterDebugger.trace("onResult", o);

                              //Populate our reviews table

                              for (var i:int = 0; i <o.length; i++)

                              {

                                        //get our current name / rating / comments object

                                        var item:Object = o;

                                        var nameTxt:TextField = getChildByName("name" + (i + 1)) as TextField;

                                        var ratingTxt:TextField = getChildByName("ratings" + (i + 1)) as TextField;

                                        var commentTxt:TextField = getChildByName("comments" + (i + 1)) as TextField;

                                        //test if we have a name

                                        if (item.name)

                                        {

                                                  nameTxt.text = item.name;

                                                  ratingTxt.text = item.ratings;

                                                  commentTxt.text = item.comments;

                                        }

                              }

                    }

                    private function onFail(o:Object):void

                    {

                              trace("Failed");

                              MonsterDebugger.trace("onFail", o);

                    }

                    private function setupConnection():void

                    {

                              trace("Setting up gateway connection");

                              //Create a new net connection

                              conn = new NetConnection();

                              //Connect to the net connection

                              conn.connect("http://localhost/amfphp/gateway.php");

                    }

          }

and heres the php coding which i dont think theres anything wrong with but ypu never know

          public function __construct()

          {

                    //Connect to our database using PDO

                     $this->dbh = new PDO('mysql:host=localhost;dbname=yomo_db', 'root', 'root');

          }

          //Adding the review to database

          public function addReview($name, $ratings, $comments)

          {

                    //Prepare and sql statement for adding a review to the database

                    $stmt = $this->dbh->prepare('INSERT INTO yomo_reviews (name, ratings, comments) VALUES (?, ?, ?)');

                    //Bind our values to the statement

                    $stmt->bindValue(1, $name);

                    $stmt->bindValue(2, $ratings);

                    $stmt->bindValue(3, $comments);

                    //Execute the statement

                    $stmt->execute();

                    //REturn statement if success or fail

                    return $stmt;

          }

          //get all the reviews from the database

          public function getReviews()

          {

                    //Query the database for all reviews

                    $query = $this->dbh->query('SELECT * FROM yomo_reviews LIMIT 4');

                    //fetch all the results

                    $result = $query->fetchAll(PDO::FETCH_ASSOC);

                    //return the results

                    return $result;

          }

any help will be much appreciated at this point in time

This topic has been closed for replies.
Correct answer Ned Murphy

I can't say for sure that this involves both errors, but it seems like it might.  In one line you appear to call two functions when you create a new Responder

     var res:Responder = new Responder(onResult, onFail);

Both of those functions require an argument to be passed to them, which you name as "o" in the function definitions.

In onResult function that "o" value is used to specify a loop control value.  But if you do not pass the object then it will be null... which will account for the 1009 error when you try to use o.

The 2007 error might be talking about that missing argument.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Braniac
August 17, 2013

I can't say for sure that this involves both errors, but it seems like it might.  In one line you appear to call two functions when you create a new Responder

     var res:Responder = new Responder(onResult, onFail);

Both of those functions require an argument to be passed to them, which you name as "o" in the function definitions.

In onResult function that "o" value is used to specify a loop control value.  But if you do not pass the object then it will be null... which will account for the 1009 error when you try to use o.

The 2007 error might be talking about that missing argument.

mavenniAuthor
New Participant
August 17, 2013

take into account im a newbie to linking php and flash! so my patience is a bit low when things dont work well

my aim of call of both functions was to use it to handle the return from the database?

so how do i pass the object in the onResult function if i havent already?