dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: cannot embed images

  1. #1
    Junior Member
    Join Date
    Aug 2016
    Posts
    11

    cannot embed images

    Hi all , i am following a tutorial.

    The code below should load two images into my scene.

    I have an .as file and an .fla file in a folder called src and two images in a folder called images. I am compiling my .as file in Adobe Animate.

    When I try to embed my images using:



    [Embed(source="../images/background.jpg")]



    it does not want to work.

    Nothing is loaded and there are no errors compiled.

    I am using an .as file to control an .fla file compiling with Adobe Animate. The tutorial is using Flash Builder. Im not sure if I can use this format:

    [Embed(source="../images/background.jpg")]


    Here is my code. It is simple. It should load background.jpg and character.png from the images folder.In order to control the character onstage with keyboard controls.




    package

    {

    import flash.display.Sprite;

    import flash.display.DisplayObject;

    import flash.events.KeyboardEvent;

    import flash.ui.Keyboard;

    import flash.events.Event;



    public class BasicScrolling extends Sprite

    {

    //Embed the background image

    [Embed(source="../images/background.jpg")]

    public var BackgroundImage:Class;

    public var backgroundImageisplayObject = new BackgroundImage();

    public var background:Sprite = new Sprite();



    //Embed the character image

    [Embed(source="../images/character.png")]

    public var CharacterImage:Class;

    public var characterImageisplayObject = new CharacterImage();

    public var character:Sprite = new Sprite();



    //Create and initialize the vx and vy variables

    public var vx:int = 0;

    public var vy:int = 0;



    public function BasicScrolling()

    {



    //Add the background

    background.addChild(backgroundImage);

    stage.addChild(background);

    background.x = -1325;

    background.y = -961;



    //Add the character

    character.addChild(characterImage);

    stage.addChild(character);

    character.x = 225;

    character.y = 150;



    //Add the event listeners

    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);

    stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);

    stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);

    }



    public function keyDownHandler(event:KeyboardEvent):void

    {

    if (event.keyCode == Keyboard.LEFT)

    {

    vx = -5;

    }

    else if (event.keyCode == Keyboard.RIGHT)

    {

    vx = 5;

    }

    else if (event.keyCode == Keyboard.UP)

    {

    vy = -5;

    }

    else if (event.keyCode == Keyboard.DOWN)

    {

    vy = 5;

    }

    }

    public function keyUpHandler(event:KeyboardEvent):void

    {

    if (event.keyCode == Keyboard.LEFT

    || event.keyCode == Keyboard.RIGHT)

    {

    vx = 0;

    }

    else if (event.keyCode == Keyboard.DOWN

    || event.keyCode == Keyboard.UP)

    {

    vy = 0;

    }

    }

    public function enterFrameHandler(event:Event):void

    {

    //Move the background

    background.x -= vx;

    background.y -= vy;



    //Check the stage boundaries

    if (background.x > 0)

    {

    background.x = 0;

    }

    else if (background.y > 0)

    {

    background.y = 0;

    }



    else if (background.x < stage.stageWidth - background.width)

    {

    background.x = stage.stageWidth - background.width;

    }



    else if (background.y < stage.stageHeight - background.height)

    {

    background.y = stage.stageHeight - background.height;

    }

    }

    }

    }



    I pasted all of my code here. I hope that this is ok.

    Any help is most appreciated.

  2. #2
    Junior Member
    Join Date
    Aug 2016
    Posts
    11
    Guys i'm not sure why there are big green grins on my code. The lines should read:

    public var backgroundImageisplayObject = new BackgroundImage();

    public var characterImageisplayObject = new CharacterImage();

  3. #3
    Junior Member
    Join Date
    Aug 2016
    Posts
    11
    Not sure why my code has green grins should be a D.

  4. #4
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,804
    There's an option to disable smilies in the advanced editor for flashkit.
    From this link: https://stackoverflow.com/questions/...class/14549463
    It looks like you need to convert the class into a bitmap before you can add it as a display object. I can look into this further to verify but I'm fairly confident that this is the issue.
    .

  5. #5
    Junior Member
    Join Date
    Aug 2016
    Posts
    11
    Thanks swak, I had a typo in my class name. duh! Thanks again.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center