Results 1 to 2 of 2

Thread: [RESOLVED] Extending objects & classes???

Hybrid View

  1. #1
    Join Date
    May 2009

    resolved [RESOLVED] Extending objects & classes???

    I'm trying to manage a movie list with some options of adding a new movie and removing a movie.
    when I try to add a movie, by adding an array = new Class(); I get nothing! I'm trying to reprint the movie list, hoping the newly added movie will also be printed but no... it's not there. I've tried using alerts and firebug to see where it fails and I still haven't figured out where, so here's my code... hope you can help me!
    //The constructor
    function movieClass(moviePhoto, movieName, movieDirector, movieYear, movieGenre, movieCast, moviePlot, movieRank){
        this.mPhoto = moviePhoto;
        this.mName = movieName;
        this.mDirector = movieDirector;
        this.mYear = movieYear;
        this.mGenre = movieGenre;
        this.mCast = movieCast;
        this.mPlot = moviePlot;
        this.mRank = movieRank;
    var arr = 0;
    var movieArr = new Array();
    movieArr[arr++] = new movieClass("img/therock.jpg", "The Rock", "Michael Bay", "1996", "Action", "Sean Connery, Nicolas Cage, Ed Harris", "A group of U.S. marines, under command of a renegade general, take over Alcatraz and threat San Francisco Bay with biological weapons. A chemical weapons specialist and the only man to have ever escaped from the Rock are the only ones who can prevent chaos.", "9");
    movieArr[arr++] = new movieClass("img/independenceday.jpg", "Independence Day", "Roland Emmerich", "1996", "Action | Sci-Fi", "Will Smith, Bill Pullman, Jeff Goldblum", "The aliens are coming and their goal is to invade and destroy. Fighting superior technology, Man's best weapon is the will to survive.", "8");
    movieArr[arr++] = new movieClass("img/thematrix.jpg", "The Matrix", "Andy & Larry Wachowski", "1999", "Action | Sci-Fi", "Keanu Reeves, Laurence Fishburne, Carrie-Anne Moss", "A computer hacker learns from mysterious rebels about the true nature of his reality and his role in the war against the controllers of it.", "9");
    movieArr[arr++] = new movieClass("img/lordoftherings.jpg", "The Lord Of The Rings", "Peter Jackson", "2001", "Action | Fantasy", "Sean Astin, Sean Bean, Orlando Bloom", "In a small village in the Shire a young Hobbit named Frodo has been entrusted with an ancient Ring. Now he must embark on an Epic quest to the Cracks of Doom in order to destroy it.", "10");
    movieArr[arr++] = new movieClass("img/austinpowers.jpg", "Austin Powers in Goldmember", "Jay Roach", "2002", "Comedy | Action", "Mike Myers, Beyoncé Knowles, Seth Green", "Upon learning that his father has been kidnapped, Austin Powers must travel to 1975 and defeat the aptly-named villain Goldmember - who is working with Dr. Evil.", "7");
    //why this doesn't work???
    function addMovie(){
        var newMovName = document.getElementById("newMovieName").value; //simple text input
        var arrend = movieArr.length;
        movieArr[arrend] = new movieClass("blah source", newMovName, "blah blah");
    I know after refreshing the browser the new movie will be removed anyway, this is just for exercise purposes.

    Thank you!

    (I've added the printMovieList function, it works and prints the movie list that already exist but maybe you'll find that it causes the problem...)
    function printMovieList(){
        var movieListBody = '<p><strong>Movie List</strong></p><ul>';
        for (var i = 0; i < movieArr.length; i++) {
        		movieListBody += '<li>';	
    		var photo = movieArr[i].mPhoto;
    		movieListBody += '<img src="' + movieArr[i].mPhoto + '" alt="moviephoto" class="alignleft" />';
            movieListBody += '<div class="idfloat">' + "#" + (i) + '</div><p><strong>Name:</strong> ' + movieArr[i].mName + '</p>' + '<p><strong>Director:</strong> ' + movieArr[i].mDirector + '</p>' + '<p><strong>Year:</strong> ' + movieArr[i].mYear + '</p>' + '<p><strong>Genere:</strong> ' + movieArr[i].mGenre + '</p>' + '<p><strong>Cast:</strong> ' + movieArr[i].mCast + '</p><br />' + '<p><strong>Plot:</strong> ' + movieArr[i].mPlot + '</p><br />' + '<p><strong>Rating:</strong> ' + movieArr[i].mRank + '</p>';
            movieListBody += '</li>';
        movieListBody += '</ul>';
        document.getElementById('content').innerHTML = movieListBody;
    Last edited by liorry; 06-13-2009 at 01:53 AM.

  2. #2
    Join Date
    May 2009
    I made a mistake using input submit instead of button

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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