I’m working on getting some objects to spawn in what will eventually be a game, while simultaneously trying to grasp how to properly do the OOP and external as files methods that AS3 and Flash 5 do. Talk about jumping in the deep end of things.
I keep getting error:
ReferenceError: Error #1056: Cannot create property Gem on gawain.smileyGems.Gems.
Whenever I try to call up my Gems object. The weird thing is that the other two objects, which have been created in Flash Pro the same exact way, are loading just fine.
Code from my main as file, Engine.as
package gawain.smileyGems {
import flash.display.MovieClip
import flash.display.Stage
public class Engine extends MovieClip
{
public function Engine() {
// constructor code
var smiley_mc = new Smiley(stage);
stage.addChild(smiley_mc);
trace(smiley_mc);
var pinkParticle_mc = new PinkParticle();
stage.addChild(pinkParticle_mc);
trace(pinkParticle_mc);
var myGems_mc = new Gems();
//stage.addChild(myGems_mc);
trace(myGems_mc);
}
}
}
Code for my other objects, like pinkParticle.as
package gawain.smileyGems {
import flash.display.MovieClip
public class PinkParticle extends flash.display.MovieClip {
public function PinkParticle() {
// constructor code
x = 50;
y = 50;
}
}
}
Code for my Gems object, Gems.as (As you can see, it’s the same as the working PinkParticle code above.)
package gawain.smileyGems {
import flash.display.MovieClip
public class Gems extends flash.display.MovieClip {
public function Gems() {
// constructor code
x = 50;
y = 50;
}
}
}
Smiley.as is a bit complicated, it’s got a bunch of stuff related to the player movement, but commenting spawning it out of the main loop doesn’t make a difference to the above error. So I think everything is fine there. I’ve even tried removing it, and Gems still won’t spawn right.
The resulting log I get from running all this:
[object Smiley][object PinkParticle]
ReferenceError: Error #1056: Cannot create property Gem on gawain.smileyGems.Gems.
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at gawain.smileyGems::Gems()[C:\Users\DarkGriffin\Documents\My Dropbox\Flash\Flash Game Projects\Smiley Gems 2\Flash game\gawain\smileyGems\Gems.as:7]
at gawain.smileyGems::Engine()[C:\Users\DarkGriffin\Documents\My Dropbox\Flash\Flash Game Projects\Smiley Gems 2\Flash game\gawain\smileyGems\Engine.as:21]
As you can see, it spawns the objects Smiley and PinkParticle just fine, but once it tries to actually run the creation for Gems.as, it spontaneously crashes out. The really weird thing is that the property it is trying to make is called “Gem”, not “Gems”. “Gem” was the really old name of the object, and has long been edited out of the entire file, library, and code. I’ve already tried restarting my system and reloading flash to see if it’s some weird memory issue, but with the same results when I run my app.
Have I hit a known snag, or did I somehow corrupt things? As a new user I have no idea what to do when this happens or what could cause it.
Searches for the error message pulled up a couple solutions but those only applied if I had these objects in the scene in the editor. My actual fla is just a blank stage set in properties to use gawain.smileyGems.Engine as the class. From what I understand and observe, this setup is how one is supposed to go about using such external files to “properly” code in Flash?
I’d appreciate any input on this issue. I honestly don’t know what my next step should be anymore. PinkParticle works fine, and is actionscripted on it’s timeline just like the Gems object(for animation purposes).
If you need it to look at, I could zip the files and upload it, but I’d have to replace the graphics first since they are my custom animated stuff for my game.