Question

so far I've been completely stumped by this and I've been a few days at it, and most links I've followed and searches I've done have led me to nothing.

I want to make a simple game, with a mouse interface, but I also wanted to add a preloader. I was initially using minibuilder, as it is cross-platform and I am on Linux, but all the tutorials I saw to add a preloader seemed to be incompatible with it.

Thus I moved to just using the Flex compiler and a text-editor directly, but I haven't had much luck, and even the preloader (which seems to be the only think that actually works) is a mere copy from a tutorial that, by chance, worked.
Ideally, I'd want to merely use the MXML file to point to the preloader - having a CustomPreloader.as file for the preloader - and to start the Actionscript classes, possibly using FlashPunk along with my code to help.

This is code so far, for each of the files except CustomPreloader.as, as the preloader is already working: (Note: All files are in ~/ASClasses/src )

File: ASClasses.mxml
--------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    backgroundColor="#333333"
    creationComplete="init();"
    width="800" height="500"
    frameRate="60"
    preloader="CustomPreloader"
>
<mx:Script>
<![CDATA[

//This part is mostly for testing purposes
//========================================
import mx.controls.Alert;
public function init():void {
    Alert.show("The first function works.");
}

//And this is what I actually wanted to do
//========================================
import Application;
//Whenever I uncomment the following line, some error is thrown and the init function stops working at all.
//public var myApp:Application = new Application;
//addChild(myApp);

]]>
</mx:Script>
</mx:Application>
File: Application.as
--------------------
package{
    import flash.display.Shape;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.display.Sprite;

    public class Application extends Sprite{
        public function Application(){
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            stage.frameRate = 60;
            rotationX = -45;
            var s:Shape = new Shape;
            s.x = 400;
            s.y = 200; 
            s.rotation = 90;
            addChild(s);
        }
        addEventListener('enterFrame', function(e:Event):void{
            s.rotation += 2.5;
        } );
    }
}

However, uncommenting the line required to add Application.as seems to just throw an error, so I think that I am either missing some code or that I did something wrong.

Is there anyone who could teach me more about this, please? And although I'd like to say that I have some experience with Actionscript, at this point I've already stressed myself out so much about being unable to do this that I'd rather, if it's not too much to ask, be explained in a simple way, assuming I have no previous knowledge.

Additionally, if there are any full-blown simple tutorials for making a simple/simplistic game/demo this way, I'd appreciate that as well, as most tutorials I've seen so far only document Flex and Actionscript, and easily get complicated before I've actually managed to do anything.

Thanks in advance.

Edit 1: Also, it may be worth mentioning that the way it currently is it still manages to throw the Alert after loading.

Was it helpful?

Solution

Try

this.rawChildren.addChild(myApp);

Instead of

addChild(myApp);

Application extends Container, And When you add a child to Container, the child should implement the IUIComponent interface. Because the sprite class doesn't implements the interface, it will give you an error.

Here is some info about this Container addChild

EDIT

put the adding application code into a function,Like

public function init():void {
    Alert.show("The first function works.");

    var myApp:Application = new Application();
    this.rawChildren.addChild(myApp);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top