开发者

declare variable in flex vs flash?

开发者 https://www.devze.com 2023-03-05 20:49 出处:网络
This code gives an error Description 1026: Constructor functions must be instance methods.joe.mxml/joe/srcline 7Flex Problem

This code gives an error Description

1026: Constructor functions must be instance methods. joe.mxml /joe/src line 7 Flex Problem

Why. This is how I declare public variables in flash. Why doesn't it work in Flex? I also tried var joe:String="winning"; still doesn't work.

<fx:Script>
    <![CDATA[
        var joe="winning";
        function changelabel()
        {
            myButton.label=joe; 
        }

    ]]>
</fx:Script>
<s开发者_运维问答:Button x="50" y="42" label="Button" id="myButton" click="changelabel()"/>


I think you're running into this issue because your variable name (joe) is the same as your MXML file's name. Therefore when it sees something called "joe" in the code, it assumes that that's the constructor - and it's getting confused because the constructor is a string instead of an instance method.

Does that make sense?

Just change the name of your string variable from "joe" to "myString".

Also, pay attention to the warnings Flash Builder is giving you - it may seem trivial, but you really should specify access modifiers for all methods and properties (ie instead of "var myString" make it "public var myString".

Also, you will want to specify data types for both variables and functions.

protected var myString:String protected function changeLabel():void

These measures, taken now, will help you to write better code that's easier to manage moving forward.

Good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号