Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 861233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:56:46+00:00 2026-05-15T08:56:46+00:00

This is what I got so far, and it’s not working at all :(

  • 0

This is what I got so far, and it’s not working at all 🙁 all the variables are null in my player class and update never gets called.

I mean a programming class, not a css class. I.E. not (.movingdiv{color: #ff0000;})

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Class Test</title>
        <meta charset="utf-8" />
        <style>
            body { text-align: center; background-color: #ffffff;}
            #box { position: absolute; left: 610px; top: 80px; height: 50px; width: 50px; background-color: #ff0000; color: #000000;}
        </style>

        <script type="text/javascript">
            document.onkeydown=function(event){keyDown(event)};
            document.onkeyup=function(event){keyUp(event)};
            var box = 0;

            function Player () {
                var speed = 5;
                var x = 50;
                var y = 50;
            }

            function update() {
                box.style.left = this.x + "px";
                box.style.top = this.y + "px";
                box.innerHTML = "<h6 style=\"margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px;\">X: "+ this.x + "<br /> Y: " + this.y + "</h6>";
            }

            var player = new Player();
            var keys = new Array(256);
            var i = 0;
            for (i = 0;i <= 256; i++){
                keys[i] = false;
            }

            function keyDown(event){
               keys[event.keyCode] = true;
            }

            function keyUp(event){
               keys[event.keyCode] = false; 
            }

            function update(){
                if(keys[37]) player.x -= player.speed;
                if(keys[39]) player.x += player.speed;

                player.update();
            }

            setInterval(update, 1000/60);
        </script>
    </head>

    <body>
        <div id="box" ></div> 
        <script type="text/javascript">
            box = document.getElementById('box');
            box.innerHTML = "<h6 style=\"margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px;\">X: "+ player.x + "<br /> Y: " + player.y + "</h6>";
        </script>

    </body>
</html>

Edit: alright, I think I messed up here. The first time I tried to make a class I seem to have messed up. After retrying I seem to be able to now using the “1 Using a function” in Meders post.

the real problem seems to be that javascript doesn’t know what to do when it gets to this line in my real code:

box.style.background-position = "" + -(this.frame * this.width) + "px " + -(this.state * this.height) + "px";

It also seems to choke anytime I put

box.style.background-color

So the question I need answered now is how do I set a value to style variables in javascript that have a “-” in the name. I’ll post a test in a second

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:56:46+00:00Added an answer on May 15, 2026 at 8:56 am

    According to this article, there are three ways to define a class in JavaScript:

    1 Using a function

    Example:

     function Apple (type) {
         this.type = type;
         this.color = "red";
         this.getInfo = getAppleInfo;
     }
    
     function getAppleInfo() {
         return this.color + ' ' + this.type + ' apple';
     }
    
    
     var apple = new Apple('macintosh');
     apple.color = "reddish";
     alert(apple.getInfo());
    

    2 Using JSON

     var apple = {
         type: "macintosh",
         color: "red",
         getInfo: function () {
             return this.color + ' ' + this.type + ' apple';
         }
     }
    
    
     apple.color = "reddish";
     alert(apple.getInfo());
    

    3 Singleton using a function

     var apple = new function() {
         this.type = "macintosh";
         this.color = "red";
         this.getInfo = function () {
             return this.color + ' ' + this.type + ' apple';
         };
     }
    
    
     apple.color = "reddish";
     alert(apple.getInfo());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this far: :~ curl -u username:password -d status=new_status http://twitter.com/statuses/update.xml Now, how can
I've got this class, let's call it Refund (because that's what it's called). I
Here is what I've got so far.. I'm using this as a keybind. I
I'm trying to implement a Haskell Bag (multiset). So far I've got this data
So this is as far as I got. Before I spend days throwing darts
I post this previously in Adobe Forum but haven't got any answers so far.
This question got me thinking about the max_size method in vector class. It is
I got this code from our frontend guy for headings: <h2 class=headline><span>Foobar</span></h2> The span
I got this far: ProcessStartInfo procInfo = new ProcessStartInfo(@C:\a\a.exe); procInfo.CreateNoWindow = true; procInfo.Arguments =
I'm a beginner at setting up spring web-applications. I got this far but now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.