A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: can't override namespace functions

  1. #1
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,140

    can't override namespace functions

    this is killing me, I can't seem to override a custom name space function, flash will not accept it. Here's my classes, very simple:

    Code:
    package {
    	import flash.display.Sprite;
    
    	/**
    	 * @author Chris Foulston
    	 */
    	public class Main extends Sprite {
    
    		public function Main() {
    			
    			var t1:TestBase = new TestBase();
    			var t2:TestSubClass = new TestSubClass();
    			
    			t1.doSomethingElse();
    			t2.doSomethingElse();
    			
    			use namespace test;
    			
    			t1.doSomething();
    			t2.doSomething();
    		}
    	}
    }

    Code:
    package {
    
    	/**
    	 * @author Chris Foulston
    	 */
    	public class TestBase {
    
    		public function TestBase() {
    		}
    		
    		test function doSomething():void {
    			
    			trace("[TestBase] doSomething with namespace");
    		}
    		
    		public function doSomethingElse():void {
    			
    			trace("[TestBase] doSomethingElse");
    		}
    	}
    }
    Code:
    package {
    
    	/**
    	 * @author Chris Foulston
    	 */
    	public class TestSubClass extends TestBase {
    
    		public function TestSubClass() {
    			super();
    		}
    		
    		test override function doSomething():void {
    			
    			use namespace test;
    			
    			super.doSomething();
    			
    			trace("[TestSubClass] doSomething with namespace");
    		}
    		
    		public override function doSomethingElse():void {
    			
    			super.doSomethingElse();
    			
    			trace("[TestSubClass] doSomethingElse");
    		}
    	}
    }
    Code:
    package {
    /**
     * @author Chris Foulston
     */
    public namespace test;
    }
    everything in one package and this is the error I get:

    TestSubClass.as(12): col: 3 Error: Namespace was not found or is not a compile-time constant.

    test override function doSomething():void {


    any ideas?
    lather yourself up with soap - soap arcade

  2. #2
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,140
    guessing this can't be done then?

    Still haven't found any information about it.
    lather yourself up with soap - soap arcade

  3. #3
    Senior Member
    Join Date
    Jan 2006
    Location
    USA
    Posts
    383
    "use namespace" has to be used at the class declaration level, if I'm not mistaken.

    I can't test this right now, but does this work?

    Code:
    package {
    
    	/**
    	 * @author Chris Foulston
    	 */
    	public class TestSubClass extends TestBase {
                              use namespace test;
    		public function TestSubClass() {
    			super();
    		}
    		
    		test override function doSomething():void {
    			
    			super.doSomething();
    			
    			trace("[TestSubClass] doSomething with namespace");
    		}
    		
    		public override function doSomethingElse():void {
    			
    			super.doSomethingElse();
    			
    			trace("[TestSubClass] doSomethingElse");
    		}
    	}
    }

  4. #4
    Member
    Join Date
    Jul 2005
    Location
    Brisbane, Australia
    Posts
    66
    Add this to the class definitions in which you want to access the test namespace, so Main and TestBase.

    PHP Code:
    protected namespace test "test.namespace" 

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