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.
Related
I'm building a spritesheet class. Hopefully this will be low hanging fruit to someone, but I'm stumped.
I have a spritesheet (.png) that I've loaded at runtime and placed a section of it on the stage using this code from within the Spritesheet class .as file ouside of the constructor method:
private function onLoad(e:Event):void
{
var loaderBmp:Bitmap = Bitmap(_loader.content);
_bmpData.copyPixels(loaderBmp.bitmapData, new Rectangle(0,0,80,80),new Point(0,0));
}
That works fine. I get my slice of the .png file displaying nicely. In my case, the spritesheet is meant for animating a character, so I need to update the BitmapData and I'm not having any luck. Here is what I'm trying this within my Main class in a function I use to alter the frame of the animation depending on the state of the character:
c._thisSpriteSheet._loader.content.bitmapData.copyPixels(loaderBmp.bitmapData, new Rectangle(0,20,50,30),new Point(0,0));
loaderBmp is a variable who's value is var loaderBmp: Bitmap = Bitmap(_spriteSheet._loader.content);
c is a reference to the Runner object that is the character.
_spriteSheet is a property of the Runner class of type Spritesheet.
_loader is a property of the c._spriteSheet and is the Loader object used when the spritesheet was instantiated.
It doesn't throw an error, but it also doesn't replace the original bitmapData object with the new one. I thought maybe this meant that I need to create a new BitmapData object and use that in the copyPixels method, but that returned the same results (nothing). When I step through the code in debug mode, everything looks like it is working, but my display object does not update with the new bitmapData. What am I tripping on?
Thanks for looking!
Well, probably no one will read this since I'm answering it so quickly, but I literally spent 3 days trying to figure this out. Sometimes trying to ask the question in a concise way helps one answer their own question, and moments later, voila!
So in case anyone has a similar issue, what I was doing wrong was that I was trying to access the BitmapData object via the Loader that originally loaded it. Then it dawned on me that I could simply reference the BitmapData directly via that property of the SpriteSheet class I had made. I think this will be pretty confusing for someone else to follow. If a moderator sees this and thinks it's junk, I don't mind it getting erased, but thought I'd keep it up anyway. The new code looked like this:
c._thisSpriteSheet._bmpDSheet.copyPixels(loaderBmp.bitmapData, new Rectangle(0,20,50,30),new Point(0,0));
and _bmpDSheet is the bitmapdata property of the class.
I have asked this question on the http://www.actionscript.org/ forums, I have yet to get a reply, so I will try here as well, I will copy the post from those forums, but please do tell me if I am missing any details out, posting it on the wrong forum on this website, or whether I should actually post it to another website.
The post is as follows:
I am fairly new to using action script 3.0, I am following a set of video tutorials for such.
I am using Adobe Flash Professional CC 2014, along with some extra elements, to create the main menu for a game using UDK(Unreal Development Kit), that I have in mind, to confirm, this is a test game, not intended for release, it will be free to try when I get various features implemented, a practice project.
So, I am using Scaleform and CLIK. When I run what I have so far, using the Scaleform launcher, everything works as intended, no errors are logged in the console. However, when I use the debugger and click on the 'Options' button on my main menu (it is the only button in frames 1-10, at the moment, under the 'mainMenuScreen' label that I have declared), I get the following error:
ArgumentError: Error #2109: Frame label default not found in scene default.
at flash.display::MovieClip/gotoAndPlay()
at scaleform.clik.controls::Slider/draw()[C:\UDK\UDK-2014-08\Development\Flash\AS3\CLIK\scaleform\clik\contr ols\Slider.as:273]
at scaleform.clik.controls::Slider/set value()[C:\UDK\UDK-2014-08\Development\Flash\AS3\CLIK\scaleform\clik\contr ols\Slider.as:156]
at MainMenu_fla::MainTimeline/frame10()[MainMenu_fla.MainTimeline::frame10:11]
at flash.display::MovieClip/gotoAndPlay()
at MainMenu_fla::MainTimeline/OpenGameplayOptionsScreen()[MainMenu_fla.MainTimeline::frame1:17]
I am not using a label known as 'default', nor do I have a scene called 'default' and also, as can be seen from the code for the button, I am not trying to go to (gotoAndPlay), 'default', I am trying to go to a label I have defined, known as 'gameplayOptionsScreen', the code is as follows:
import flash.events.MouseEvent;
/*Function
#Name: OpenGamePlayOptionsScreen
#Params: None
#Description: This function will make the scene go to the "gameplayOptionsScreen"
label, so that the components that will be on the screen will now be those under the
label of "gameplayOptionsScreen".
*/
function OpenGameplayOptionsScreen(evt : MouseEvent)
{
gotoAndPlay("gameplayOptionsScreen");
}
// Add an event listener to this button, so it can tell if it has been clicked on, // in this case:
optionsBtn.addEventListener("click", OpenGameplayOptionsScreen);
(The line above this one, is where the debugger highlights one of the places the error occurs)
stop(); // Stop the flash movie here
From what problems that the debugger has informed me of, it also seems to have a problem with the slider that appears in frame 10, the frame that the label, 'gameplayOptionsScreen', is assigned too.
But I am wondering why the error occurs, in regards to a call to 'gotoAndPlay("gameplayOptionsScreen");', as that is where I believe the error becomes existent from.
Please do tell me if you require more information to help me solve this problem that I am having, or do tell me if I have posted this in the wrong forum on this website, or if I have in fact posted this to the wrong website altogether and therefore, should be posting to Epic Games' forums instead.
Edit: I have redone the button, so that, it is now known as TestGameButton and DefaultButton is in my library too, as it was in the click components library, this component has been left unchanged this time. Using my new button still produces the same errors and even using the default button does as well. But removing the slider that the debugger also complains about that is displayed in frame 10, removes all the errors, so it seems to be a problem with the slider, I am not sure what though, I have tried putting in a new instance and naming it, but I get similar errors .
Never mind then, I don't mind if this question does not get any answers, I am moving onto UE4, which has much better systems in place for menus, for example, thanks for trying to help #CyanAngel though.
Suppose you are using flash builder(4.7) with flash professional (or bringing in flash professional assets in a swc or swf) and you have the whole screen in one symbol. So then you want to pull everything out into a variable. Something like this:
_pictureThing = _startScreen["pictureThing"] as Sprite.
It will give you the red under bar because you haven't mentioned _pictureThing yet. So you hit ctrl+1, choose make an instance variable. Sure. But now when you go up to the top of the class, it is a String! WHAT? I said as Sprite. The only thing I would expect this to be is a Sprite. How could this possibly not be a feature of Flash Builder? It's as if they went to almost the perfect editor and then said, "Nah. Let's just not finish it. Let's just make it do this crazy camera jumping instead". Making every variable type String may seem like not a big deal, but when you have a lot of variables the time really adds up. Maybe my way just works, but isn't actually the syntax that Flash Builder wants me to write it?
Since every object has a toString() implementation, if the Flash Builder editor cannot detect the supposed type of a variable, it assumes a String as default failsafe value for its type. The question of why did FB's devs not made it parse as statement as a supposed var type setter is open, my weird suggestion will be inheritance, as Sprite is a descendant of say DisplayObjectContainer type, so maybe that var should be of that type, or maybe one level less (EventDispatcher), or maybe Object right away. Probably the fix Fygo posted in comments can make it for you:
_pictureThing = Sprite(_startScreen["pictureThing"]); – Fygo 22 mins ago
but the inheritance ambiguity still remains. I say just let it be.
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
Hi Im relatively new to flash developing and i have a quick question about saving user input. I have a maze scene whereby the user navagates a character around until confronted with another object, when the character hits the object a new scene is opened promting the user to pick a solution to a problem. Once the user clicks the correct answer a box appears saying return to the maze, however when clicked and returned to the maze the character starts back in its original postion, where as I would like the scene to resume where it left off, ie the character is at the point where it collided with the object, the object has dissappeared and the character can resume on the same course.
Thanks for giving this a read I hope it makes sense and some one has a solution for me.
I did have some nice images to explain it better but apprently i need 10 reputation points to upload those.
EDIT: First Id like to say thanks for the rep points you bunch of stars and secondly I know using scenes in flash is seriously cr*p practice and outdated but its the way I learnt all those years ago and seen as Flash itself will be outdated soon Im not really looking to learn another approach using sprites or frames, I just kind of want a fix for this way if poss thank you for answering!
EDIT: Wanting the red rectangle to be removed from the scene once the black square collides with it. It also takes you to the next frame upon doing so. here is my code.
addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
function fl_EnterFrameHandler (event:Event):void
{
if (player.hitTestObject(Risk))
{
removeEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
removeChild(Risk);
nextFrame();
}
}
I'd suggest you forget about Scenes! They are old, buggy, bring loads of issues with code and are generally a Bad Pratice!! So if you are just learning AS3, dont learn with Scenes!!
Use MovieClips or Sprites instead. And just add and remove them as you need!
EDIT:
To ur edit ;)
and seen as Flash itself will be outdated soon
thats just plain false and a widespread misinformation. It just has a new purpose like MultiPlattform Game Development. But thats a whole different discussion.
You could solve this by saving the x,y coordinates and then restoring them. But i promise you, you will run in to alot more problems/bugs as you go allong!
Like saved Points and Time. Will you triger the Questionscene again when u place the player on the object(last Position). Save the answers, and so on ...
Changing to DisplayObjects will save you time in the end. Just saying ;)
EDIT2:
your code in the comment should look like this:
function fl_EnterFrameHandler (event:Event):void
{
if (player.hitTestObject(Risk))
{
removeEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);//remove to prevent errors if it fires again and there is no Object to hitTest
removeChild(Risk);// do what needs to be done on this frame
nextFrame();// and then move to the next
}
}
And following correct convetions and make everybody's life easier reading this, it would look like this!
function fl_EnterFrameHandler (event:Event):void
{
if (player.hitTestObject(risk))
{
removeEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);//remove to prevent errors if it fires again and there is no Onject to hitTest
removeChild (risk);
nextFrame ();
}
}
i'm probaly confusing u now, just use the top one ;)
EDIT3:
Ok, i just had a butchers at it. It's all on a single Frame now. I would have prefered Classes but that'lljust confuse you.
To add new qestions you just have to dublicate the Question MovieClip in the Library and change texts, leave instance names the same tho, then the code will work as is!
DOWLOAD
It is certainly possible. You would store the characters attributes (e.g. current position) within a variable. Then on returning to your game you would use this variable to set the starting position of your character.
I agree that scenes are not the ideal route you should be taking. Possibly reading a good AS3 book would save you hours/days/weeks in the long run.