A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: No Output In My Class

  1. #1
    Senior Member
    Join Date
    May 2007
    Posts
    102

    No Output In My Class

    Hi i am using FlashDevelop and i have created the following classes,
    Vehicle.as
    PHP Code:
    package   

         
        
    /** 
         * Vehicle.as is meant to show a vehicle class 
         * @author Luong Vuong 
         * Date created: 29/09/2009 
         * Last modified: 30/09/2009 
         */ 
         
        
    import flash.display.MovieClip
        
    import flash.events.Event
         
        public class 
    Vehicle extends MovieClip  
        

            public var 
    _gasMileage:Number
            public var 
    _fuelAvailable:Number
            public var 
    _milesTraveled:Number 0
            public var 
    _go:Boolean
             
             
            
    //public var vehicle:Vehicle = new Vehicle(21, 18); 
             
            
    public function Vehicle(mpg:Number 21fuel:Number 18) :void  
            

                
    _gasMileage mpg
                
    _fuelAvailable fuel
                
    this.addEventListener(Event.ENTER_FRAMEonLoopfalse0true); 
                
    construct(); 
                   
                  
            } 
             
            public function 
    construct() :void 
            

                
    //addChild(vehicle); 
                //vehicle.go(); 
            

            public function 
    onLoop(evt:Event) :void 
            

                if (
    _go
                { 
                    
    _fuelAvailable--; 
                    
    _milesTraveled += _gasMileage
                    if ( 
    _fuelAvailable 
                    { 
                        
    this.removeEventListener(Event.ENTER_FRAMEonLoop); 
                    } 
                    
    trace(this_milesTraveled_fuelAvailable); 
                    
    this._milesTraveled
                } 
                 
            } 
             
            
    // Start engine and drive 
            
    public function go() :void 
            

                
    _go true
                 
            } 
             
              
        } 
      

    VehicleOnly.as
    Code:
    package   
    { 
         
        /** 
         * VehicleOnly.as is meant to show  
         * @author Luong Vuong 
         * Date created: 30/09/2009 
         * Last modified: 30/09/2009 
         */ 
         
        import flash.display.Sprite; 
        import flash.events.Event; 
         
        public class VehicleOnly extends Sprite  
        { 
            public var vehicle:Vehicle = new Vehicle(21, 18); 
             
             
            public function VehicleOnly() :void  
            { 
                 
                initialize(); 
                construct(); 
            } 
             
                // Initialize all variables 
            public function initialize() :void 
            { 
                addChild(vehicle);       
                     
            } 
             
            // Add listeners and add UI to display list 
            public function construct() :void 
            { 
                 
                vehicle.go(); 
                     
    
            } 
             
            // Class methods 
        } 
      
    }
    When i create an instance of the Vehicle class in my VehicleOnly.as file and send the values to my constructor, and run the appplication, it does not show any output to my Output panel. I should be getting the following:

    [object Vehicle] 21 17
    [object Vehicle] 42 16
    ...
    [object Vehicle] 336 2
    [object Vehicle] 357 1
    [object Vehicle] 378 0

    can somebody tell me exactly why i am not getting this??

    Thanks

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    Working for me...
    Files Attached.
    Attached Files Attached Files

  3. #3
    Senior Member
    Join Date
    May 2007
    Posts
    102
    Hi,

    i kind of new that it would work on Adobe IDE but, i'm sadly not using it to build my class, like i said i'm using FlashDevelop. can you try to do this on FlashDevelop because i'm still not getting any output,.

  4. #4
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    I also use FlashDevelop, but yes, I use it with Flash CS4.
    So, are you using the Flex SDK?

  5. #5
    Senior Member
    Join Date
    May 2007
    Posts
    102
    AAH LIGHT BULB!!!!! I found out what the problem was. It struck me as i was sleeping, seriusly, after tackling it for 2 hours getting slightly frustrated. The problem was not the actual code in my VehicleOnly.as file. It was that on FlashDevelop every time you create a new .as file you need to set it to "Always Compile".

    It was compiling my Vehicle.as file and not my VehicleOnly.as file, hope that makes sense.

    Sorry if i have caused any inconvenience by the way.

  6. #6
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    Sure, no problem, glad you solved it.

    Yes, that's right, you should be compiling VehicleOnly.as. When I tested it in Flash, that was the Class that I used as my Document Class.

    In the meantime I've installed the Flex SDK, which was cool.

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