views:

57

answers:

2

This is a puzzler.

Relevant Environment: Flex app, running parsley, which gets built by ant.

Problem class:

package com.foo.bar {
    public class ProblemClass {
        // constructor
        public ProblemClass(enforcer:Enforcer) {}

        public static function build():ProblemClass  {
            // Do some setup
            return new ProblemClass(new Enforcer())
    }
}
// internal private class
class Enforcer() {}

Elsewhere, in a seperate class (which gets defined in a Parsley context):

package com.foo.bar {
    public class ProblemClassBuilder {
        [Factory]
        public function getProblem():ProblemClass {
            return ProblemClass.build();
        }
      }
}

Here's the kicker: When I compile this from an ant task with debug="true", it works fine. When I compile it with debug="false", parsley throws an error while building the context:

Error applying [object FactoryMethodDecorator]: Error #1065: Variable Enforcer is not defined.

No other code changes, except turning debug on / off in the mxmlc ant task.

Has anyone seen similar problems with internal classes & ant debug compile modes?

I've been able to fix the issue, (by removing the internal class), but don't understand why it didn't work in the first place.

A: 

you are only allowed one class definition per actionscript file, otherwise you have to use the internal keyword so it should be private internal class Enforcer()

shortstick
Sorry, but this is incorrect. There is no "private" class modifier in actionscript. (http://bit.ly/9hvf5h) Additionally, you CAN declare more than one class in an actionscript file, but the subsequent classes are scoped to the default scope of the the initial class - ie., only accessible to the first class. Adding internal to this class declaration has no effect.This is a common pattern for implementing Singleton / Private classes in AS.
Marty Pitt
+1  A: 

Sounds like a bug in the compiler... I'd file it at bugs.adobe.com

Clint Modien