New to AS3, adrift on simple concept
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: New to AS3, adrift on simple concept

  1. #1
    Junior Member
    Join Date
    Mar 2014

    New to AS3, adrift on simple concept

    I'm trying to do a basic little project as a way of teaching myself as3, and I can't even get off the ground. The goal is to have two scenes, each with their own backgrounds and descriptions, that the user can go between. Step one of that is to be able to tell the game which background to load, and I can't even get that far.

    Here's what I have:

    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import flash.sampler.NewObjectSample;
    import flash.utils.getDefinitionByName;
    var curScene:int = new int(1);
    var sceneData:Array = new Array("BG_Day", "BG_Night");
    startButton.addEventListener(Event.ENTER_FRAME, fl_FadeSymbolIn);
    startButton.alpha = 0;
    startButton.enabled = false;
    function fl_FadeSymbolIn(event:Event)
    	startButton.alpha += 0.05;
    	if(startButton.alpha >= 1)
    		startButton.enabled = true;
    		startButton.removeEventListener(Event.ENTER_FRAME, fl_FadeSymbolIn);
    startButton.addEventListener(MouseEvent.CLICK, startClick);
    function startClick(event:MouseEvent):void
    	var startRaise:Tween = new Tween(startButton, "y", Regular.easeIn, startButton.y, -100, 10, false);
    	mc_bg.addEventListener(Event.ENTER_FRAME, loadCurrentScene);
    function loadCurrentScene(event:Event):void
    	var libImage:getDefinitionByName(sceneData[curScene]) = new getDefinitionByName(sceneData[curScene])();
    	var currentBG:Bitmap = new Bitmap(libImage);
    	var bgFade:Tween = new Tween(mc_bg, "alpha", Regular.easeInOut, 0, 100, 100, false);
    	mc_bg.removeEventListener(Event.ENTER_FRAME, loadCurrentScene)
    There's nothing to it at this point. It loads with a start button, whuch when clicked is supposed to load the appropriate BG. However, I'm having a hard time getting the names of the BGs out of the array where they're stored (It works fine when hard-coded). I suspect I'm using getDefinitionByName wrong. Can anyone help? I

  2. #2
    Junior Member
    Join Date
    Dec 2013
    Attached is a basic starter project for you to look at.

    Note: Download GSAP for the tweens.
    Copy the included "com" folder into the same folder as the FLA.
    test Movie.
    Clicking the "start" button will add the first scene and remove the button.
    Clicking a scene will add the next scene and remove the previous scene.
    The backgrounds are built into the scenes.
    ie: scene1, scene2, scene1, scene2, etc...

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Yeah, AS3 is very complex. Trying to go from AS2 to AS3 now, lol.

  4. #4
    Senior Member
    Join Date
    Nov 2001
    Here's example AS3 code that is as OOP free as possible. I shows good ways to do common programming stuff in AS3 - add clips dynamically to stage from library, use arrays of objects to store everything.

    Check it out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center