Embedded Image not Adding to Stage - actionscript-3

So I have an image that I'm trying to embed to use as a sprite sheet. My problem is that I am receiving no errors at all, but my image can't even be added to the stage. It's like nothing is being loaded at all.
I am using the Flash CS 5.5 compiler. Here is my code:
public class Game extends MovieClip {
[Embed(source='../assets/images/sprite_sheet_1.png')]
private var sheetClass:Class;
private var sheet:Bitmap = new sheetClass();
public function Game() {
addChild (sheet);
}
}
I've also tried fiddling with the x and y values to make sure nothing is just covering it up and I can't see any problems with that, either. It's just not showing up.
I don't understand why it's not working as intended. Any aid would be fantastic. Thanks!
P.S. - I'm trying to embed the sprite sheet because someone recommended it would be a better route than just using URLLoaders, but is that necessarily true? Is it just true because we are talking about sprite sheets for a smallish Flash game?

You need to check a checkbox called something like "Export SWC" under the publish settings. I'm not sure of the exact phrasing because I don't have the same version of Flash that you have.
See this page and this page

Related

Actionscript 3 problems with "Call to a possibly undefined method"

Thanks partly to info from people here, I'm getting more comfortable with Actionscript 3, but I've got a problem that is very puzzling.
The program (done entirely in AS3, no Flash) has several different screens. One does music and it's working very well. Another does video. Obviously when somebody goes from music to video we need to make sure the music is turned off. There is a Main screen that handles going from one to the other.
I started out doing it this way, and the reason I got "Call to a possibly undefined method" is obvious. The following is in the Main class, with the "private var" part inside the class but external to the functions and the "music = new MusicPanel" part in one of the functions:
private var music:MusicPanel;
music = new MusicPanel(trackNames.songNames, trackNames.numSongs);
When switching to the video panel, I added a public function in MusicPanel called StopMusic and called it when the user went to the video panel:
if(music != null)
music.StopMusic();
That got the error:
Call to a possibly undefined method StopMusic
I was checking to make sure music was not null, but that error didn't seem like a bad thing. So I changed the code to:
private var music:MusicPanel = new MusicPanel();
and added a function that would get the song names and number of songs to the music class. That did not help- I got the same error, and in fact the function that tried to put the song names and number of songs got the error also.
At the same time, the Video panel does not give me that error, even though I have laid it out in exactly the same way.
private var video:VideoPanel = new VideoPanel;
video.PlayVideo();
I do a fair amount of setup on the music screen when it gets called as a new class, I do less setup for the video screen. I'm not sure if that makes a difference.
Clearly there is something I don't understand here. Anybody got any idea what's going on? I've looked at a number of questions about this, but have not found an answer. I think I'm doing this right, but the compiler thinks I'm doing it wrong, so I must be doing it wrong.
Later Note: One answer mentioned the difference between Sprite and MovieClip. I gave that a try, changing to MovieClip does not help, and the VideoPanel, which works, extends Sprite.
What is the base class of MusicPanel, Sprite or MovieClip? If Sprite, change to MovieClip and see what that does. In AS3 Sprites are not dynamic, so can't take properties that are not inherent in the class.
It appears that the problem is coming either from Actionscript 3 or from FlashDevelop. I built a new module (SongsPanel) which is very close to the same as the original MusicPanel. It works. If I add a public function in MusicPanel the compiler comes back with the same error. If I add a public function in SongsPanel everything works.
Does FlashDevelop keep track of errors in some hidden file? I'm guessing that's what's going on, and that there is a bug in the way that is done.
PITA!- but at least it now works.

Using a separate .fla file as a MovieClip in a larger project

Just to preface: I haven't used Flash in a long long time, however, I am still aware of the environment.
Backstory: I created a small .fla to perform actions on a MovieClip on the stage (in my case, a health/HP bar). I made the health effect using a Document Class (HealthBar.as).
The question: What I'm trying to figure out now is how, in a totally separate .fla, to create multiple instances of these health bars and be able to access the methods in Document Class HealthBar.as from the Document Class in this new .fla
If I am doing this incorrectly in the first place, feel free to yell at me, and let me know how doing something like this SHOULD have been done.
Thanks for any help
You're halfway there with a document class. Now you just need to make it into a proper class in your com.domain.className (or drop the .as file into the same directory as your fla). While creating classfiles is trivial, online examples seem to muck it up, so here's Adobe's official demo (bleh).
That said, creating more healthbars basically looks like this...
Class
package {
public class HealthBar extends Sprite {
public function HealthBar() {
// constructor
trace("Healthbar created")
}
}
}
Document Code
import HealthBar;
for (var i:int = 0; i < 10; i++) {
var randomHealthBar:HealthBar = new HealthBar(); // <-- magic sauce
addChild(randomHealthBar);
}
// traces: "Healthbar created" 10 times
Shouldn't you be able to copy the movieclip from the healthbar .fla into your main .fla and then give it an actionscript linkage of HealthBar?
Then you should be able to call new HealthBar whenever you need one in your main file.

Starling scaffold project showing blank texture

I am building an app using Starling and have imported the scaffold project however whenever I call getTextureAtlas() it doesn't show the image
this.mLogo = new Image(Assets.getAtlasTexture("powered_by_starling"));
this.mLogo.x = 0;
this.mLogo.y = 0;
this.addChild(this.mLogo);
There are no errors so I am guessing it can find the texture. If I change the name to something that doesn't exist it throws an error 'texture cannot be null'. I am also using
Assets.contentScaleFactor = Starling.current.contentScaleFactor;
and everything is pretty much a standard import of the scaffold as is however I am using Feathers UI screen navigator but I haven't had a blank image issue on other projects.
Edit: I can't seem to get the sprite to work within a class that extends feathers.controls.Screen
Is getAtlasTexture a function that you wrote? Are you using starlings asset manager? If that's the case, you will need a instance of that class, not static method call.
Anyway, try using the Texture class and the static method it offers. You don't need atlas(sprite sheet) for a Image - you will need it however for MovieClip.
Texture.fromBitmap
Texture.fromBitmapData
.... and others, check documentation
If your graphics are embedded, then use this:
var _img:Image = new Image(Texture.fromBitmap(new Assets.EmbeddedGraphic()));
Are you using atf? because the same happened to me until I used png and then it worked

as3 Air - AddChild works but is slooooooooooow

I am creating an app where when a button is pressed a very large picture is added to the stage (it is larger than the screen but can be dragged around by the user)
When the button is pressed the picture (well, movieClip) does come up and it able to be dragged fine, buttons inside it work.
The problem though is that there is a pause of about 6 seconds between the button press and the image appearing. I am using one .fla file for publishing and compiling (let's just call it Main.fla for now), and another one to hold all the graphics. The graphics are then added with this embed command:
[Embed (source = "assets/graphic.swf", symbol = "Content")]
private var Content:Class;
private var _content:*;
I have these lines where all the variables are declared (in between the class definition and the constructor function) I was under the impression that embedding it like this was equivalent to loading it at compile time. Is this true? What could be causing this lag when the button is pressed?
If I can't cut out the lag, another idea I had was to make some spinning circle or something to tell the user, "hey, don't worry. It's loading!"
If the slowness is at addChild you can add the asset to the stage much earlier and set it's visiblility to false, then when the button is clicked set it back to true. Obviously this is a small hack but might be sufficient for what you are doing.
var asset:MovieClip;
private function init():void
{
asset = new Content();
assset.visible = false;
addChild(asset);
button.addEventListener(MouseEvent.CLICK, onMouseClick);
}
private function onMouseClick(e:MouseEvent):void
{
asset.visible = true;
}
Embedding your SWF is probably not what is causing the delay.. or rather it would not likely be better if you imported the SWF into your FLA. Is this on a device? Chances are you would either have to devise a different way of loading your asset, or be satisfied with a loading animation.
If the main K size is coming from a large image, you could consider loading it in segments, starting with the part that is initially visible.

Unable to access children in movie clip

Inside flash cs6 I have drawn a flash movieclip in which I set export settings as abc.Gameboard. Inside gameboard I have a bunch of pieces (symbol:Piece) which I export as abc.Piece - both base class set to MovieClip and with class files. The piece has frame labels like hit, over etc.. My problem is accessing the pieces in code so I can eg. gotoAndPlay("mine") - at the moment the event only fires once which is the last piece on the board.
I can set the frame action on this last piece but would like to figure out how to do same for each piece.
I add a gameboard to the stage like so
var gb:Gameboard = new Gameboard();
gb.name = "gb001";
contextView.addChild(gb);
Then
contextView.addEventListener(Event.ADDED, thingAdded);
private function thingAdded(event:Event):void
{
var type:String = event.target.toString();
switch(type)
{
// this runs only once - i want it to run for each piece that is inside the symbol
case "[object Piece]":
var p:MovieClip = event.target as Piece;
p.gotoAndPlay("mine");
break;
}
}
or if there's a better way that would be great.. this looks pretty clunky
Edit: Bit more info about how I'm trying to build the gameboard
Draw a collection of shapes in illustrator - mask it (Gameboard region). Import into Flash as Graphic. Convert graphic to several movie clip symbols (So JSFL can drill down and access masked pieces) - run JSFL script & create 00's of pieces. Then I set export settings on Piece and Gameboard and add Gameboard to the contextView.
I actually wrote an entire article about this once. The ADDED event should fire once for every DisplayObject that gets added. Are you sure that you're not using ADDED_TO_STAGE, which does not bubble? If you're using ADDED_TO_STAGE, then you need to set the useCapture flag to true to get it to fire for all children.
If you want to involve RobotLegs in the process, probably the better way is to simply create a "marker" Class for each specific button that you want to have behave in a different way, then register a mediator for each Class that will manage the behvior. Robotlegs already has the hooks built in to listen for ADDED_TO_STAGE and do this.
However, you could also consider using the Flash IDE for what it's for, which is putting stuff on stage. In that case, your GameBoard instance will be ready in the constructor of your main document Class for you to do whatever you want with it.
MPO is that logic that is outside Gameboard shouldn't know or care how it works internally, and honestly it probably shouldn't even be GameBoard's responsibility to handle simple stuff like button over states and things. That should be up to the button itself. If the buttons don't need to toggle or anything beyond what SimpleButton handles, you can just declare the button instances as Button in the library instead of MovieClip and get all that stuff for free instead of coding it yourself.
Part of being a good coder is in being able to figure out ways not to code everything.
in their Gameboard inside Piece? I want know exactly your Gameboard Structure.
If you're right. try this:
function thingAdded(e:Event):void
{
if(!e.target is Gameboard) return;
var mc:Gameboard = Gameboard(e.target);
var i:int = 0;
while(i<mc.numChildren)
{
if( mc.getChildAt(i) is Piece)
{
var piece:Piece = Piece(mc.getChildAt(i));
piece.gotoAndStop(2);
}
i++;
}
}
Here is my Sample code: Gameboard