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 7551757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:34:42+00:00 2026-05-30T10:34:42+00:00

I’m making a game where I have must have some objects like weapons and

  • 0

I’m making a game where I have must have some objects like weapons and characters, which I in the end would like to get visual as a sprite or movieclip

Should I write the logic for the objects in several classes and then make a reference to the object in a sprite class like the following :

public class WeaponModel
{

    public damage:Int = 8;

    public function Weapon(){
        //Do the constructor code
    }

    public function get damage():int{
        return this.damage;
    }
}

public class WeaponSprite extends Sprite
{

    var weaponModel:WeaponModel;

    public function WeaponSprite(weaponModel:WeaponModel){
        this.weaponModel = weaponModel;
    }
public function get weaponModel():WeaponModel{
        return this._weaponModel;
    }
}

And then when I need to do damage just call the WeaponSprite’s method weaponModel() when I need to acces the methods or should I just merge the two together into one class.?

  • 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-30T10:34:44+00:00Added an answer on May 30, 2026 at 10:34 am

    I would avoid passing a reference to the model to a view. A more decoupled approach would be to pass a model id to the view. The provide access to the model id through a getter. In general you want to keep knowledge of models out of views and knowledge of views out of models.

    Below is an example of how a controller class might manage the relationship between views and models.

    class View
    {
       public function View( modelId:int )
       {
          this._id = modelId;
       }
    
       public function get modelId():int { return this._id; }
    
       protected function doSomething():void 
       {
            dispatchEvent( new Event(Event.DOING_SOMETHING) );
       }
    }
    
    class Controller 
    {
        function init()
        {
            for each( model in models )
            {
                var view = new View( model.id );
                view.addEventListener( Event.DOING_SOMETHING, onViewDoingSomething );
            }
        }
    
        protected function onViewDoingSomething( event:Event ):void 
        {
           if( event.target is View )
           var view:View = event.target as View;
           // -- do something with view.modelId here
        }
    }
    

    Another thing to consider is how large of an application you are building and how many people will be working on it. When building a quick prototype, you may not be concerned with following strict OOP patterns. However, the larger and more complex a project gets, the more likely it is that a framework or specific design patterns will be of value to you.

    If you are interested in learning a framework that facilitates consistent and flexible designs, consider looking at Robot Legs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I have a text area in my form which accepts all possible characters from
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is

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.