• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

problem embedding images

Community Beginner ,
Oct 14, 2019 Oct 14, 2019

Copy link to clipboard

Copied

I am having a problem loading images from folder src, I am getting multiple 1120 error access of undefined property.
I have a src folder with .fla and .as files inside and a images folder with background.png and character.png images.

I was using a URLRequest and loader and displaying the images from the folder instead of embedding them. It was displaying the images so Im sure my folder hierarchy is correct. I have commented out the code there.

my code is here:

 

 

package {

import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;


public class Dungeon extends Sprite {


//create game character objects
/*public var characterURL:URLRequest = new URLRequest("../images/character.png");
public var characterImage:Loader = new Loader();
public var character:Sprite = new Sprite();*/

//embed the background image
[embed(source="../images/background.png")]
public var BackgroundImage:Class;
public var backgroundImage:DisplayObject = new BackgroundImage();
public var background:Sprite = new Sprite();

//embed the character image
[embed(source="../images/character.png")]
public var CharacterImage:Class;
public var characterImage:DisplayObject = new CharacterImage();
public var character:Sprite = new Sprite();


//Create and Initialise the vx and vy variables
public var vx: int = 0;
public var vy: int = 0;

//Add the background
background.addChild(backgroundImage);
stage.addChild(background);
background.x = -1005;
background.y = -762;

//Add the character
character.addChild(characterImage);
stage.addChild(character);
background.x = 225;
background.y = 250;


public function Dungeon() {
//Load the image into sprite and place it on the stage

/*characterImage.load(characterURL);
character.addChild(characterImage);
stage.addChild(character);
character.x = 225;
character.y = 150;*/



// 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 {
//feed the vy vx velocity to hero object position
character.x += vx;
character.y += vy;

//Stop hero from moving over the stage boundaries 50 pixels inside stage

//Top Boundaries
if (character.x < 50)
{
character.x = 50;
}
if (character.y < 50)
{
character.y = 50;
}
if (character.x + character.width > stage.stageWidth)
{
character.x = stage.stageWidth - character.width;
}
if (character.y + character.height > stage.stageHeight)
{
character.y - stage.stageHeight - character.height;
}

//Bottom Boundaries(slightly different code adds heros width

if (character.x + character.width > stage.stageWidth - 50)

{
character.x = stage.stageWidth - character.width - 50;
}
if (character.y + character.height > stage.stageHeight - 50) {
character.y = stage.stageHeight - character.height- 50;
trace("here");
}

}

}
}

 

any help is greatly appreciated.

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 14, 2019 Oct 14, 2019

which line is #22?

 

if it's: public var backgroundImage:DisplayObject = new BackgroundImage();

 

you have no referable BackgoundImage class.

Votes

Translate

Translate
Community Expert ,
Oct 14, 2019 Oct 14, 2019

Copy link to clipboard

Copied

which line of code is triggering the error?  (click publish settings and tick 'permit debugging'>retest)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 14, 2019 Oct 14, 2019

Copy link to clipboard

Copied

Hello again KGLAD.

TypeError: Error #1007: Instantiation attempted on a non-constructor.
at Dungeon()[C:\Users\Dell\Desktop\2DGame Design\Game\src\Dungeon.as:22]

 

this is what I get back.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 14, 2019 Oct 14, 2019

Copy link to clipboard

Copied

which line is #22?

 

if it's: public var backgroundImage:DisplayObject = new BackgroundImage();

 

you have no referable BackgoundImage class.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 14, 2019 Oct 14, 2019

Copy link to clipboard

Copied

Yes it is line 22. 

 

Don't I define that with this code?:

 

[Embed(source="../images/background.jpg")]
public var BackgroundImage:Class;

 

Thanks for the interest and help again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2019 Oct 15, 2019

Copy link to clipboard

Copied

yes, it does. but that's flex coding (which used to work in flash). i don't know if something's changed but if i were you, i'd use a loader.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 15, 2019 Oct 15, 2019

Copy link to clipboard

Copied

Hi thanks. Yeah, I was using the loader method. I am advised the best way is to embed the code. This way the code cannot  run before the images are loaded. Im told this can happen. Thanks for your input. Really appreciate any help.

 

I am using Animate as the IDE and not using anything but AS3 to get things done. I know how to us Animate but right now I am concentrating on pure coding. When I have some coding skills  I'm sure I will mix timeline, library and code in projects. Flash oops sorry, Animate is too well rounded a tool to ignore.  I plan on using it to make games and apps, using AIR to package across the board. I sometimes feel a bit of trepidation learning AS3 as it is not at all fashionable right now. Nobody seems to be learning it. I am hoping that I can learn AS3 to harness the power of Flash and also  learn the programming knowledge which can be applied to other languages in the future. As far as I can see Javascript is almost identical to AS3.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 15, 2019 Oct 15, 2019

Copy link to clipboard

Copied

OK it's working. I moved the code that adds the images to screen to the constructor. I tried this before and could not get it to work. Worls now. 

 

Thanks for the input, kglad. 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2019 Oct 15, 2019

Copy link to clipboard

Copied

you're welcome. p.s. the using a loader does not load the image until the loader.load() code executes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2019 Oct 15, 2019

Copy link to clipboard

Copied

if you're planning to publish for mobiles, there's a problem with animate.  adobe stopped developing air and has transferred development to harmon (and harmon charges money and maybe other issues).

 

i've dropped animate for mobile development and moved to unity.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 19, 2019 Oct 19, 2019

Copy link to clipboard

Copied

Thanks for the heads up kglad. 

I thought I would get the basics of OOP down with AS3 . Will AS3 transfer to Javascript HTML5?

Im not worried about the html or the CSS. I would like to be learning some transferable skills here though.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 19, 2019 Oct 19, 2019

Copy link to clipboard

Copied

there are a lot of similarities between as3 and javascript (js) though whether js is really on oop language is debatable.  there's definitely not a rigid class structure like java, as3 and c#.

 

i'm not sure it's worth investing time to work with as3 anymore.  if you're thinking of making mobile apps i think you should check unity.

 

if you want to make html5/canvas applications, animate is still a viable choice.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 22, 2019 Oct 22, 2019

Copy link to clipboard

Copied

I really appreciate your input. I have  invested 2 months into AS3 and I am realising I will have the ability to produce  something a lot more complex than I thought. As I learn, new ideas are forming of what is possible. I don't want to break that flow. So I think I will continue to learn AS3 for my first project-I feel that I need to make something, not get bogged down in new syntax. Then - I will take stock of where I am.

 

I have been looking into how else AS3 is used. There is so much to learn. It is overwhemling at times but also very exciting.

Javascript, HAXE  for cross platform as well.

I started skimming a book on HTML5 using Javascript, CSS and HTML. It is by the same author  and has the same projects(even the same graphic assets) as I am working through now only they are re-written for HTML5. To be honest, the HTML at this level seems basic and css easy. I have been thinking about  going this route in the future.

 

I would really value your opinions on my options. Thanks for all of your help and interest. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 22, 2019 Oct 22, 2019

Copy link to clipboard

Copied

what are you planning to do with as3?

 

you can't create mobile apps (that you plan to deploy on google play and ios apps have significant limitations, ios<11) without purchasing air from harman (and it's not clear to me what support you're purchasing with this).  in addition, all ane's need to be updated with harman's air or they will android/ios app rejection.

 

and you can't build air apps for the latest mac osx.

 

so, the only use i see is creating win desktop apps, and i don't know how long that statement will remain true.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 22, 2019 Oct 22, 2019

Copy link to clipboard

Copied

what are you planning to do with as3?

 

I thought I might  try to produce some childrens apps. Simple drag and drop stuff to begin with. Animate can export to both android and ios. or could?

Im not frightened of learning unity though. I am multimedia designer, so applications don't scare me. 

I would like to finish something now I have started. Just a 2d platformer at least for my own satisfaction before moving on.

How different is C#  to AS3?

Also what about HTML5 route?

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 22, 2019 Oct 22, 2019

Copy link to clipboard

Copied

animate can publish to both ios and android but google play is requiring 64bit and that means creating your app and then dealing with harmon's air 33+ or deal with harmon and then start working on your app.

 

and ios 11+ requires 64 bit so that requires dealing with harmon's air 33+ either before or after your make your app.

 

for mobile apps, unity offeres everything animate does plus a lot more (and it's free unless you're a major developer).  the syntax of c# is different from as3 but otherwise all the major concepts are the same.  the ide of unity is way more sophisticated than animate.  the help files are much better organized.  the tutorials are much better organized.

 

i started learning unity 2 months ago and i'm well on my way to creating an android app for a client.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2019 Oct 23, 2019

Copy link to clipboard

Copied

yes, harmon is charging - a minmum $200/yr:  https://airsdk.harman.com/download

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 23, 2019 Oct 23, 2019

Copy link to clipboard

Copied

Thanks for the input kglad. I am going to go with HTML5.  Is coding corner here a good resource for javascript?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2019 Oct 23, 2019

Copy link to clipboard

Copied

i don't know that.  i just google all my questions.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 24, 2019 Oct 24, 2019

Copy link to clipboard

Copied

So you do some Javascript development? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 24, 2019 Oct 24, 2019

Copy link to clipboard

Copied

yes.

 

this i made using jquery mobile and coding in a text editor (sublime text), http://calhi-montevista.com

 

and this i made mostly using animate (and some hand coding using sublime text), http://www.kglad.com/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 29, 2019 Oct 29, 2019

Copy link to clipboard

Copied

Hi KGLAD, I just thought I would drop a line to tell you I have started to study HTML5 

and it is twisting my head, LOL. Juggling CSS, HTMLand Javascript is more difficult than I thought. Seems to be very different to AS3. 

Thanks for all the help.

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2019 Oct 30, 2019

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines