com.hurlant.util.hex syntax error on air sdk 3.5

巧了我就是萌 提交于 2019-12-11 04:33:01

问题


I have an application written and compiled with an older version of flex sdk. Now i have to port this application to run on mobile devices, so i changed the sdk to air sdk 3.5. I'm using hurlant library for encryption/decryption. bu on Hex class there is a line that throws an error.

    if (hex.length&1==1) hex="0"+hex;

I dont know what (hex.length&1==1) means. So how should i have to change the line or is there any other solutions for that problem?


回答1:


I've seen that error too, it happens when you compile with the new ASC2.0 compiler of Flash Builder 4.7.

I changed if (hex.length&1==1) hex="0"+hex; into

 if ((hex.length&1)==1) hex="0"+hex;

and that fixed it.




回答2:


if(hex.length&1==1) means that checks whether hex.length is Odd-numbered(1,3,5,7...).

refer a as follows:

var str:String = "111";

if(str.length&1==1)
{
   str = "0" + str;

   trace(str);
}

your syntax no problem. I'm sure that. what kind of error show to?

I have a Hex.as. but no occur any syntax error. In Flash Builder 4.6, Flash CS6 AIR3.5.

package com.hurlant.util
{
    import flash.utils.ByteArray;

    public class Hex
    {
        /**
         * Support straight hex, or colon-laced hex.
         * (that means 23:03:0e:f0, but *NOT* 23:3:e:f0)
         * Whitespace characters are ignored.
         */
        public static function toArray(hex:String):ByteArray {
            hex = hex.replace(/\s|:/gm,'');
            var a:ByteArray = new ByteArray;
            if (hex.length&1==1) hex="0"+hex;
            for (var i:uint=0;i<hex.length;i+=2) {
                a[i/2] = parseInt(hex.substr(i,2),16);
            }
            return a;
        }

        public static function fromArray(array:ByteArray, colons:Boolean=false):String {
            var s:String = "";
            for (var i:uint=0;i<array.length;i++) {
                s+=("0"+array[i].toString(16)).substr(-2,2);
                if (colons) {
                    if (i<array.length-1) s+=":";
                }
            }
            return s;
        }

        /**
         * 
         * @param hex
         * @return a UTF-8 string decoded from hex
         * 
         */
        public static function toString(hex:String):String {
            var a:ByteArray = toArray(hex);
            return a.readUTFBytes(a.length);
        }


        /**
         * 
         * @param str
         * @return a hex string encoded from the UTF-8 string str
         * 
         */
        public static function fromString(str:String, colons:Boolean=false):String {
            var a:ByteArray = new ByteArray;
            a.writeUTFBytes(str);
            return fromArray(a, colons);
        }

    }
}



回答3:


you will need both, flex and air!
looks like a typo to me..

if (hex.length==1) hex="0"+hex;

depending on what that if statement should look for

EDIT MY Bad
I didn't know about that Operator, i would have done that with a modulus!
I bow to your superior skills.



来源:https://stackoverflow.com/questions/15337453/com-hurlant-util-hex-syntax-error-on-air-sdk-3-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!