A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Referencing a clip on stage not working

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    17

    Referencing a clip on stage not working

    In a new document when I create a movie clip on the stage and reference it in a script in the first keyframe, like aaa.scaleX = 0.2;, everything works fine.

    But when I try this in the game I'm making, I get this error "1120: Access of undefined property aaa.". Why?

    In my game I use a document class, here is the code that is executed at the beggining.

    Actionscript Code:
    package
    {

        import flash.display.MovieClip;
        import flash.display.Stage;
        import flash.utils.*;
        import flash.events.TimerEvent;
        import flash.events.MouseEvent;
        import flash.ui.Mouse;
        import flash.display.Sprite;
        import flash.text.*;
        import flash.events.Event;
        import flash.events.KeyboardEvent;
        import flash.ui.Keyboard;
        import flash.media.SoundChannel;
        import flash.media.SoundTransform;

        public class Engine extends MovieClip
        {
            public var loopEventCounter:int; //for level events
            public var generalsCount:int = 0;

            public var enemies:Array = new Array  ;
            public var enemyGuns:Array = new Array  ;
            public var missiles:Array = new Array  ;
            public var shipmissiles:Array = new Array  ;
            public var bullets:Array = new Array  ;
            public var bulletexplosions:Array = new Array  ;
            public var bulletexplosions2:Array = new Array  ;
            public var bulletexplosionradius:Array = new Array  ;
            public var exhausts:Array = new Array  ;

            public var k:int;
            public var j:int;
            public var i:int;
            public var w:int;
            public var v:int;
            public var l:int; // menagement variable

            public var healthDisplay:HealthDisplay;
            public var redFlash:RedFlash;
            public var fadeOut:FadeOut;
            public var fadeIn:FadeIn;
            public var swarmIndicator:SwarmIndicator;
            public var ship:Ship;
            public var intro:Intro;

            public var playButtan:PlayButtan;
            public var mainMenu:MainMenu;
            public var options:Options;
            public var levelSelectionScreen:LevelSelectionScreen;
            public var deathMenu:DeathMenu;
            public var escMenu:EscMenu;
            public var debriefing:Debriefing;
            public var textFieldContainer:TextFieldContainer;

            public var gun:Gun;
            public var gun2:Gun;
            if(Vars.antiMissileTurret)
            {public var gun3:Gun;} //-------------------------------------------------------------------?????
            public var enemyGun:Gun;

            public var headLights:HeadLights;
            public var movingBackground:MovingBackground;
            public var movingBackgroundClouds:MovingBackgroundClouds;
            public var movingBackgroundClouds2:MovingBackgroundClouds2;
            public var exhaust:Exhaust;
            public var shipExhaust:ShipExhaust;

            public var radiance:Number = 180 / Math.PI;

            var enemy:Enemy;
            var missile:Missile;
            var shipMissile:Missile;
            var bullet:Bullet;
            var bulletExplosion:BulletExplosion;
            var bulletExplosion2:BulletExplosion2;
            public var bulletExplosionRadius:BulletExplosionRadius;

            var fpsCounter:FPSCounter;

            public var gameTimer:Timer;
            public var gameTimerSlow:Timer;
            public var dying:Timer = new Timer(6000); //DIE TIME
            /*public var delayTextFade:Timer;
            public var textFadeRepeater:Timer;*/

            public var delayTextFade;
            public var textFadeRepeater;
            public var bulletTimeInterval;

            public var mouseButtonIsBeingPressed:Boolean;
            public var spaceBarIsBeingPressed:Boolean;
            public var missileReloadSoundPlayed:Boolean;

            public var ticksSinceLastShot:int;
            public var ticksSinceBulletTime:int = 100;
            public var ticksSinceLastAntiShot:int;
            public var enemyMissilesAmount:int;
            public var enemyGunsAmount:int;
            public var activeBarrel:int = 1;

            //
            public var eventTimer:int = 1;
            public var microEventTimer:int = 1;
            //

            public var bulletHit:BulletHit;
            public var bulletHit2:BulletHit2;
            public var bulletHit3:BulletHit3;
            public var bulletHit4:BulletHit4;
            public var bulletHit5:BulletHit5;
            public var bulletHit6:BulletHit6;
            public var machineGun:MachineGun;
            public var machineGun2:MachineGun2;
            public var machineGun3:MachineGun3;
            public var missilesReload:MissilesReload;
            public var missileLaunch:MissileLaunch;
            public var lowExplosion:LowExplosion;
            public var smallExplosion:SmallExplosion;

            public var sfxSoundChannel:SoundChannel;
            public var soundTransformMute = new SoundTransform  ;
            public var soundTransformVolumeControl = new SoundTransform  ;

            public function Engine () // ------------------------------------------------- ENGINE START
            {
                loadEngine(); //some basic functions

            }

                     public function loadEngine ()
            {
                addEventListener(Event.ADDED_TO_STAGE,onAddToStage,false,0,true);

                sfxSoundChannel = new SoundChannel  ;
                soundTransformMute.volume = 0;
                soundTransformVolumeControl.volume = 0.3;

                mouseButtonIsBeingPressed = false;
                spaceBarIsBeingPressed = false;
            }

  2. #2
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    That aaa is not in the code anywhere.

    Please provide the code throwing the error.

  3. #3
    Junior Member
    Join Date
    Apr 2010
    Posts
    17
    aaa.scaleX = 0.2; is the code that is throwing the error, placed in the first frame.

    There is a movie clip on the stage called aaa.

  4. #4
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    Did you name the instance? An instance of the 'aaa' symbol could be on stage but if it's not named, the compiler won't recognize it.

    Refer to picture attached:
    Attached Images Attached Images

  5. #5
    Junior Member
    Join Date
    Apr 2010
    Posts
    17
    Yeah, I did. As I said, the same setup works flawlessly on a new fla file...

  6. #6
    bibuti. nolen's Avatar
    Join Date
    Sep 2002
    Location
    az.
    Posts
    191
    So you have code on the first frame AND you're using a document class?
    i'm obsessed with video games.

  7. #7
    Junior Member
    Join Date
    Apr 2010
    Posts
    17
    Yes, because I want to add a preloader, and I don't know how to do it via document class... all the tutorials are for code in the first frame.

  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Make your document class dynamic. The way properties corresponding to display instances get there in the first place is that Flash assigns dynamic properties by instance name. If your class is not dynamic, it cannot accept those properties.

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