You're right that MyComponent calls
the function without specifying scope, which means that "this" is
going to be MyComponent. However you wrote myCustomFormatter in another
class, and it compiled as if it was meant to run in the scope of that other
class (meaning "this" will be that other class). Remember how
many posts I wrote on the beta forum to address this issue? That's
what we want to avoid.
Matt
-----Original Message-----
From: Samuel R. Neff [mailto:[EMAIL PROTECTED]
Sent: Tuesday, May
11, 2004 9:58 PM
To: [EMAIL PROTECTED]
Subject: RE: [flexcoders]
Compilation error "Only functions in the document are allowed"
I don't see how there is any scoping issue as any
component that receives a
property/style of type Function calls that
function without any specific
scope as in:
<MyComponent formatter="myCustomFormatter"
/>
class MyComponent {
var formatter:Function;
function doSomething() {
var whatever = formatter(data);
}
}
Best regards,
Sam
> -----Original Message-----
> From: Matt Chotin
[mailto:[EMAIL PROTECTED]
> Sent: Tuesday, May 11, 2004 1:43 PM
> To: '[email protected]'
> Subject: RE: [flexcoders] Compilation error
"Only functions
> in the document are allowed"
>
> You can try binding including a Delegate if
necessary. I'll
> file a bug and see if there's a way I can get
the compiler to
> do the right thing. I believe the
question we had at the
> time was this: what scope should that
function execute in if
> it lives in another document. By
forcing the function to
> live on the document we know the scope is
going to be the
> document where you made the function call, so
it's easy and
> everyone understands what's happening.
But I you assign a
> function from outside the document, is it
supposed to execute
> in the scope of the document where the
function is defined,
> in the scope of your document where the
component is defined,
> or in the scope of the component that's
calling the function
> (a la normal behavior if you don't use a
Delegate, also the
> most confusing for many people)? If you
all have opinions
> let's hear them and we can look into
implementing that in a
> future release.
>
>
>
> Matt
>
>
>
> -----Original Message-----
> From: Samuel R. Neff
[mailto:[EMAIL PROTECTED]
> Sent: Tuesday, May 11, 2004 10:34 AM
> To: [email protected]
> Subject: [flexcoders] Compilation error
"Only functions in
> the document are allowed"
>
>
>
>
> Seems the compiler has a restriction on
declaratively setting
> values of
> "Function" type properties and
styles. If I do this:
>
>
> <bl:HorizontalClusteredBarChart
>
formatPointLabelFunction="PointLabelFormatters.myPointFormatter"
/>
>
>
> Where PointLabelFormatters is defined as:
>
>
> class PointLabelFormatters {
>
> public static function
myPointFormatter(point:Object):String {
> return "this is
my point";
> }
> }
>
>
> I get an error:
>
>
> Error /charts/CustomPoints.mxml:19
> Only functions in the document are allowed.
>
>
> Even if I try to create a document level
alias for the function:
>
>
> <mx:Script>
> var
localAliasForSillyCompilerRestriction:Function =
> PointLabelFormatters.myPointFormatter;
> </mx:Script>
> <HorizontalClusteredBarChart
>
formatPointLabelFunction="localAliasForSillyCompilerRestriction"
/>
>
>
> I get the same error. Only workaround
is to create a wrapper
> function which
> means an extra unnecessary function call just
because of a compiler
> restriction. This is a function that
will be called
> thousands of times upon
> each rendering, so the extra call can be
significant.
>
> Is there any other way around this besides
the wrapper function?
>
> Sam
>
>
>
> ----------------------------------------
> Blog http://www.rewindlife.com
> TeamMM http://www.macromedia.com/go/team
> ----------------------------------------
>
>
>
>
>
>
>
>
> ________________________________
>
> Yahoo! Groups Links
>
>
> * To visit your
group on the web, go to:
> http://groups.yahoo.com/group/flexcoders/
>
> * To
unsubscribe from this group, send an email to:
>
[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>
>
> * Your use of
Yahoo! Groups is subject to the Yahoo!
> Terms of Service <http://docs.yahoo.com/info/terms/>
.
>
>