A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Code working in Flash but not Flex...why?

  1. #1
    Member
    Join Date
    Apr 2009
    Posts
    62

    Question Code working in Flash but not Flex...why?

    I have this code creates a function at runtime (yes, this IS needed):
    PHP Code:
    var createdFunction = function():void {
        
    trace("Function Created");
    }

    createdFunction(); 
    Putting in in to the actions panel in Flash CS4 and compiling works fine, tracing the message "Function Created"...

    However, the Flex compiler gives me this
    Error: Call to a possibly undefined method createdFunction.
    createdFunction();
    Build halted with errors (fcsh).
    Check out my firefox theme "PacStrata" here

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I was able to compile this with the flex 4 compiler with only a warning about createdFunction being untyped (why wouldn't you give it a type?). Typing it as * or Function results in exactly what you would expect.
    Code:
    package 
    {
    	import flash.display.Sprite;
    	import flash.events.Event;
    	
    	/**
    	 * ...
    	 * @author srs
    	 */
    	public class Main extends Sprite 
    	{
    		
    		public function Main():void 
    		{
    			if (stage) init();
    			else addEventListener(Event.ADDED_TO_STAGE, init);
    		}
    		
    		private function init(e:Event = null):void 
    		{
    			removeEventListener(Event.ADDED_TO_STAGE, init);
    			// entry point
    			var createdFunction:Function = function():void {
    				trace("Function Created");
    			}
    			createdFunction(); 
    		}
    		
    	}
    	
    }
    Last edited by 5TonsOfFlax; 08-27-2009 at 08:10 PM.

  3. #3
    Member
    Join Date
    Apr 2009
    Posts
    62
    Don't know much about types since I'm quite new at AS3 (It's so different to the old AS2)...but your code works perfect...thanks!
    Check out my firefox theme "PacStrata" here

Tags for this Thread

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