Skip to main content
April 28, 2009
Answered

Using a preloader in a separate AS file?

  • April 28, 2009
  • 2 replies
  • 1102 views

Hey folks,

I've appropriated a preloader I created previous where it existed on the main timeline. For my new project, I placed it in an external AS file, but something's off. I keep getting this error message, referencing line 16 in my line of code:

"1046: Type was not found or was not a compile-time constant: Event."

The code is below:

package {
    import flash.display.MovieClip;
    import flash.events.Event.ENTER_FRAME;
    import flash.events.MouseEvent;
    import MainNav;
    import Gallery;
    import MP3Player;

    public class ZDSite extends MovieClip{
        stop();
        private var total:Number = stage.loaderInfo.bytesTotal;
        private var loaded:Number = stage.loaderInfo.bytesLoaded;
       
        addEventListener(Event.ENTER_FRAME, loading);
       
        private function loading(event:Event):void {
            //add in load bar here later: Bar_mc.scaleX = loaded/total;
            //add in load text box here late: txtLoaded.text = Math.floor((loaded/total)*100)+ "%";
            //add more load stuff here later
            if (total == loaded) {
                play();
                removeEventListener(Event.ENTER_FRAME, loading);
                //add in function to check if current frame = 60 and stop there
                //add in MainNav, Gallery, and MP3Player to bring objects to stage here
            }
        }
    }
    public class MainNav extends MovieClip {
        //insert Main Nav Stuff here
    }
    public class Gallery extends MovieClip {
        //insert Gallery stuff here
    }
    public class MP3PLayer extends MovieClip {
        //insert MP3 Player stuff here
    }
}

Any insight would be appreciated. Thanks!

This topic has been closed for replies.
Correct answer kglad

try:

package {
    import flash.display.MovieClip;
    import flash.events.*;
    import MainNav;
    import Gallery;
    import MP3Player;

 

    public class ZDSite extends MovieClip{
       // stop();
        private var total:Number = stage.loaderInfo.bytesTotal;
        private var loaded:Number = stage.loaderInfo.bytesLoaded;
       
        function ZDSITE(){
        stop();
        addEventListener(Event.ENTER_FRAME, loading);         }                private function loading(event:Event):void {             //add in load bar here later: Bar_mc.scaleX = loaded/total;             //add in load text box here late: txtLoaded.text = Math.floor((loaded/total)*100)+ "%";             //add more load stuff here later             if (total == loaded) {                 play();                 removeEventListener(Event.ENTER_FRAME, loading);                 //add in function to check if current frame = 60 and stop there                 //add in MainNav, Gallery, and MP3Player to bring objects to stage here             }         }     }     public class MainNav extends MovieClip {         //insert Main Nav Stuff here     }     public class Gallery extends MovieClip {         //insert Gallery stuff here     }     public class MP3PLayer extends MovieClip {         //insert MP3 Player stuff here     } }

2 replies

May 5, 2009

I'm still coming up with problems with the same error messages and I can't seem to get around it. Any ideas?

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 5, 2009

try:

package {
    import flash.display.MovieClip;
    import flash.events.*;
    import MainNav;
    import Gallery;
    import MP3Player;

 

    public class ZDSite extends MovieClip{
       // stop();
        private var total:Number = stage.loaderInfo.bytesTotal;
        private var loaded:Number = stage.loaderInfo.bytesLoaded;
       
        function ZDSITE(){
        stop();
        addEventListener(Event.ENTER_FRAME, loading);         }                private function loading(event:Event):void {             //add in load bar here later: Bar_mc.scaleX = loaded/total;             //add in load text box here late: txtLoaded.text = Math.floor((loaded/total)*100)+ "%";             //add more load stuff here later             if (total == loaded) {                 play();                 removeEventListener(Event.ENTER_FRAME, loading);                 //add in function to check if current frame = 60 and stop there                 //add in MainNav, Gallery, and MP3Player to bring objects to stage here             }         }     }     public class MainNav extends MovieClip {         //insert Main Nav Stuff here     }     public class Gallery extends MovieClip {         //insert Gallery stuff here     }     public class MP3PLayer extends MovieClip {         //insert MP3 Player stuff here     } }
May 6, 2009

Yup, placing the addEventListener as a single (and first) method did the trick, thanks!

kglad
Community Expert
Community Expert
April 28, 2009

add:

import flash.events.Event;

April 28, 2009

I made the changes, but I am now getting two more error messages regarding line 13:

"1180: Call to a possibly undefined method addEventListener." and "1120: Access of undefined property loading.

kglad
Community Expert
Community Expert
April 28, 2009

is the flash that contains a ZDSite movieclip being published for as3?