Skip to main content
Known Participant
October 19, 2019
Question

using a class to display an image

  • October 19, 2019
  • 1 reply
  • 208 views

I posted this earlier in animate forum. Hope it is ok to repost here.

I am embedding an image in its own class called character.

the code for the class is here:

package{

import flash.display.DisplayObject;
import flash.display.Sprite;

public class Character extends Sprite
{

[Embed(source="../images/character.png)]
public var GameObjectImage:Class;
public var gameObjectImage:DisplayObject = new GameObjectImage();

public function Character()
{

this.addChild(gameObjectImage);
}

}

}

 

Then in my application class I create a new character object like this:

public var character:Character = new Character();

 

Then in a function i called createGameobjects I add the object to the stage with:

 

addGameObjectToStage(character, 50, 50);

 

which uses this function also in the application class:

 

public function addGameObjectToStage(gameObject:Sprite, xPos:int, yPos:int):void
{
stage.addChild(gameObject);
gameObject.x = xPos;
gameObject.y = yPos;
}

 

I just cant get this working. I was embedding images straight into the application class, I am advised to load all images into their own class  now. 

 

The errors I get point to the Character class.

 

thanks in advance guys.

 

    This topic has been closed for replies.

    1 reply

    Known Participant
    October 20, 2019

    I solved the problem. I don't know how. But I used the same technique I described in a new .as file and it works great.