You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by Justin Mclean <ju...@classsoftware.com> on 2017/02/12 06:18:56 UTC

[FlexJS] Uncaught type exception

Hi,

I trying something perhaps a little too complex fro FlexJS. First off does FlexJS support binding on setters/getters yet?

I have this code:
<?xml version="1.0" encoding="utf-8"?>
<js:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:js="library://ns.apache.org/flexjs/basic"
               xmlns:comp="components.*">

   <js:valuesImpl>
       <js:SimpleCSSValuesImpl/>
   </js:valuesImpl>
   <js:initialView>
       <js:View id="base" percentWidth="100" percentHeight="100">
            <comp:Box no="3" colour="red" />
       </js:View>
   </js:initialView>
</js:Application>

And this component:

<?xml version="1.0"?>
<js:Container xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:js="library://ns.apache.org/flexjs/basic">

   <js:beads>
     <js:ContainerDataBinding />
   </js:beads>

   <fx:Script><![CDATA[

       protected var _colour:String;

       [Bindable]
       public var no:int;

       [Bindable]
       public function set colour(colour:String):void {
           bigBox.style = "background-color:" + colour + ";text-align:center;";
       }

       [Bindable]
       public function get colour():String {
           return _colour;
       }
       ]]></fx:Script>

       <js:Container id="bigBox" height="32" width="32" style="background-color:#E3E3E3;text-align:center;">
           <js:Label text="{no}" style="line-height:32px;font-size:150%:font-weight:bold" />
       </js:Container>
</js:Container>

When I run the application I get this exception.

Box.js:88 Uncaught TypeError: Cannot set property 'style' of undefined
   at components.Box.__bindingWrappedSetter__colour (Box.js:88)
   at components.Box.bindable__set__colour (Box.js:124)
   at components.Box.set__colour (Box.js:135)
   at Function.org.apache.flex.utils.MXMLDataInterpreter.initializeStrandBasedObject (MXMLDataInterpreter.js:158)
   at Function.org.apache.flex.utils.MXMLDataInterpreter.generateMXMLArray (MXMLDataInterpreter.js:95)
   at Function.org.apache.flex.utils.MXMLDataInterpreter.generateMXMLInstances (MXMLDataInterpreter.js:218)
   at org.apache.flex.core.View.org.apache.flex.core.ContainerBase.addedToParent (ContainerBase.js:149)
   at Main.org.apache.flex.core.Application.addElement (Application.js:116)
   at Main.org.apache.flex.core.Application.initialize (Application.js:55)
   at Main.org.apache.flex.core.Application.start (Application.js:212)
components.Box.__bindingWrappedSetter__colour @ Box.js:88
components.Box.bindable__set__colour @ Box.js:124
components.Box.set__colour @ Box.js:135
org.apache.flex.utils.MXMLDataInterpreter.initializeStrandBasedObject @ MXMLDataInterpreter.js:158
org.apache.flex.utils.MXMLDataInterpreter.generateMXMLArray @ MXMLDataInterpreter.js:95
org.apache.flex.utils.MXMLDataInterpreter.generateMXMLInstances @ MXMLDataInterpreter.js:218
org.apache.flex.core.ContainerBase.addedToParent @ ContainerBase.js:149
org.apache.flex.core.Application.addElement @ Application.js:116
org.apache.flex.core.Application.initialize @ Application.js:55
org.apache.flex.core.Application.start @ Application.js:212
(anonymous) @ index.html:108

I think that the setter is being called before bigBox exists. Debugging the code I can see that this.numElements is 0 inside the colour method.

Thanks,
Justin

Re: [FlexJS] Uncaught type exception

Posted by Alex Harui <ah...@adobe.com>.

On 2/12/17, 1:39 AM, "piotrz" <pi...@gmail.com> wrote:

>Alex,
>
>In case of raised jira by Justin - do you think that bug is inside
>compiler
>or do you want me to look into that?

You are welcome to look into it.  Maybe you or Justin can build the exact
same test case in regular Flex so we can compare how Flex handles this.
The Flex version should not use the typical invalidateProperties pattern
and directly apply a property to a child element.

It may turn out not to be a bug per-se.  We might be generating the exact
same code, and the difference is that in FlexJS we are trying to see how
far we can go without putting in a whole invalidation subsystem.

Thanks,
-Alex


Re: [FlexJS] Uncaught type exception

Posted by piotrz <pi...@gmail.com>.
Alex,

In case of raised jira by Justin - do you think that bug is inside compiler
or do you want me to look into that?

Piotr



-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/FlexJS-Uncaught-type-exception-tp59245p59253.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [FlexJS] Uncaught type exception

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> Binding works mostly.  It looks like the generated code might need a
> try/catch.  File a bug.

https://issues.apache.org/jira/browse/FLEX-35262 <https://issues.apache.org/jira/browse/FLEX-35262>

> Yes, that is probably the case.  If your properties are being applied to
> objects being created later you may have to defer the application of those
> properties.  That was true in regular Flex as well.

Code like this would work in regular Flex so there may be a little more going on here.

Thanks,
Justin

Re: [FlexJS] Uncaught type exception

Posted by Alex Harui <ah...@adobe.com>.

On 2/11/17, 10:18 PM, "Justin Mclean" <ju...@classsoftware.com> wrote:

>Hi,
>
>I trying something perhaps a little too complex fro FlexJS. First off
>does FlexJS support binding on setters/getters yet?

Binding works mostly.  It looks like the generated code might need a
try/catch.  File a bug.

>
>I think that the setter is being called before bigBox exists. Debugging
>the code I can see that this.numElements is 0 inside the colour method.

Yes, that is probably the case.  If your properties are being applied to
objects being created later you may have to defer the application of those
properties.  That was true in regular Flex as well.

Properties get applied early, children are created later.  Most of our
other components have a model so properties applied early are set in the
model and children pull their data from the model when created.

-Alex