Copy link to clipboard
Copied
Hello lovely ActionScript Guru's -
I am new to learning AS3, and have run into roadblock after roadblock with getting what I think should be a simple thing working. I am attempting to create a tiered menu using a MovieClip that contains Simple Buttons. I am running into 2 different problems while publishing what I have built -
1. My Menu.as (code below), claims that it requires "5000: The class "Menu" must subclass 'flash.display.SimpleButton' since it is linked to a library symbol of that type." This is fine, except when I do change the code to reflect the change that the error message wants me to fix, my beautiful animated menu with options turns into an absolutely useless picture, with no ability to be used as a menu at all. I have read from other forums that I what I am missing is to create a MovieClip that contains buttons, however I believe that that is exactly what I have done. I am unsure how to fix this error.
2. When compiling, my main class (ConsStartMenu.as) will not complete compiling because of an error 1119: on line 29 and 46, claiming that my link to my subclass (Menu.as) is calling a potentially undefined property Menu through a reference with static type ConsStartMenu. After googling and browsing forums for many hours, I still have absolutely no idea what this error means, or what it wants me to fix. I believe that this is also the reason why my resizing and centering code is not functioning. It's like it cannot find my Menu.as at all. Perhaps a quick peek at my code will shed some light on this?
Thank you very much in advance for your help.
- connor
ConsStartMenu.as -
package {
import flash.display.MovieClip;
//import some stuff from the valve lib
import ValveLib.Globals;
import ValveLib.ResizeManager;
public class ConsStartMenu extends MovieClip{
//these three variables are required by the engine
public var gameAPI:Object;
public var globals:Object;
public var elementName:String;
public function ConsStartMenu() : void {
}
//this function is called when the UI is loaded
public function onLoaded() : void {
//make this UI visible
visible = true;
//let the client rescale the UI
Globals.instance.resizeManager.AddListener(this);
trace("Cons Start Menu loaded!");
this.Menu.setup(this.gameAPI, this.globals);
}
public function onResize(re:ResizeManager) : * {
var scaleRatioY:Number = re.ScreenHeight/900;
if (re.ScreenHeight > 900){
scaleRatioY = 1;
}
this.Menu.screenResize(re.ScreenWidth, re.ScreenHeight, scaleRatioY);
}
}
}
Menu.as -
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.display.SimpleButton;
public class Menu extends MovieClip {
var gameAPI:Object;
var globals:Object;
public function Menu() {
}
public function setup(api:Object, globals:Object) {
//set our needed variables
this.gameAPI = api;
this.globals = globals;
}
public function screenResize(stageX:int, stageY:int, scaleRatio:Number){
//position 'this', being this module, at the center of the screen
this.x = stageX/2;
this.y = stageY/2;
//save this movieClip's original scale
if(this["originalXScale"] == null)
{
this["originalXScale"] = this.scaleX;
this["originalYScale"] = this.scaleY;
}
//Scale this module/movieClip by the scaleRatio
this.scaleX = this.originalXScale * scaleRatio;
this.scaleY = this.originalYScale * scaleRatio;
}
}
}
you're missing a fundamental understanding of classes and how they work.
the bottom line: you can't reference Menu unless it's a static class.
you should be creating an instance of your Menu class:
var menu:Menu = new Menu();
and then you may want to add that to your ConsStartMenu use addChild(menu), or maybe you don't. i can't tell.
is ConsStartMenu your document class?
Copy link to clipboard
Copied
you're missing a fundamental understanding of classes and how they work.
the bottom line: you can't reference Menu unless it's a static class.
you should be creating an instance of your Menu class:
var menu:Menu = new Menu();
and then you may want to add that to your ConsStartMenu use addChild(menu), or maybe you don't. i can't tell.
is ConsStartMenu your document class?
Copy link to clipboard
Copied
Ok, I think this is starting to make a bit more sense, now that I've looked through quite a few class tutorials. I've decided to simplify my code and expectations a little bit.
Here's what I've built, first of all -
My document, ConsStartMenu.fla, contains within it's library a MovieClip called Menu. This MovieClip contains multiple different frames, each with coding and intelligence contained within its Actions tab right on the frame. I couldn't figure out how to get button intelligence to work within Menu.as, so I've given up on that idea completely and am doing all of my intelligence within the frames itself.
On the properties tab of ConsStartMenu.fla, my class definition there is ConsStartMenu. I think that makes it the document class, right?
What I want to do is -
1. Place my MovieClip called Menu into the center of my stage ConsStartMenu.fla, using code.
2. Figure out the resolution of the person opening the clip, and accurately move the Menu MovieClip to the center of their screen, even if their resolution is different from my original stage.
I hope that helps simplify what I'm asking, and clarifies a few things. Thank you very, very much for your help so far - just having a direction to look has made all the difference.
New ConsStartMenu.as -
package {
import flash.display.MovieClip;
//import some stuff from the valve lib
import ValveLib.Globals;
import ValveLib.ResizeManager;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
public class ConsStartMenu extends MovieClip
{
//these three variables are required by the engine
public var gameAPI:Object;
public var globals:Object;
public var elementName:String;
public var scaleRatioy:Number;
public var ScreenHeight:Number;
var Menu:MovieClip = new MovieClip;
addChildAt(Menu,1);
public function ConsStartMenu() : void {
}
//this function is called when the UI is loaded
public function onLoaded() : void {
//make this UI visible
visible = true;
//let the client rescale the UI
Globals.instance.resizeManager.AddListener(this);
trace("Cons Start Menu loaded!");
}
}
}
New Menu.as -
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.display.SimpleButton;
public class Menu extends MovieClip {
var gameAPI:Object;
var globals:Object;
public function Menu() {
}
}
}
Copy link to clipboard
Copied
you're message is truncated/incomplete.
Copy link to clipboard
Copied
Should be updated now - apparently Ctrl-S posts on this forum instead of saves. Let me know if it's there now.
Copy link to clipboard
Copied
yes, that's better.
is everything working as expected?
if so, when using the adobe forums, please mark helpful/correct responses, if there are any.)
Copy link to clipboard
Copied
Unfortunately, no. However, after much more messing about, I finally got it all working. Here's the final configuration, without scaling (couldn't figure that out), but with both placing the MovieClip on the stage, and centering it based upon the resolution of the user -
Thanks for your help!
package {
import flash.display.MovieClip;
//import some stuff from the valve lib
import ValveLib.Globals;
import ValveLib.ResizeManager;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
public class ConsStartMenu extends MovieClip
{
//these three variables are required by the engine
public var gameAPI:Object;
public var globals:Object;
public var elementName:String;
public var scaleRatioy:Number;
public var ScreenHeight:Number;
public var menuDisplay:Menu = new Menu();
public function ConsStartMenu() : void {
addChild(menuDisplay);
menuDisplay.x=stage.stageWidth * .5;
menuDisplay.y = stage.stageHeight * .5;
}
//this function is called when the UI is loaded
public function onLoaded() : void {
//make this UI visible
visible = true;
//let the client rescale the UI
Globals.instance.resizeManager.AddListener(this);
trace("Cons Start Menu loaded!");
this.menuDisplay.setup(this.gameAPI, this.globals);
}
public function onResize(re:ResizeManager) : * {
//Calculate scale ratio
var scaleRatioY:Number = re.ScreenHeight/900;
//If the screen is bigger than our stage, keep elements the same size (you can remove this)
if (re.ScreenHeight > 900){
scaleRatioY = 1;
}
//pass the resize event to our module, we pass the width and height of the screen, as well as the correctedRatio.
this.menuDisplay.screenResize(re.ScreenWidth, re.ScreenHeight, scaleRatioY);
}
}
}
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now