开发者

operator overload in as3 workarounds

开发者 https://www.devze.com 2023-02-17 06:11 出处:网络
I know it\'s not possible to overload operators in as3, and have been using the get and set functionality (which is brilliant imho), however now I\'m in the middle of creating a colour class.

I know it's not possible to overload operators in as3, and have been using the get and set functionality (which is brilliant imho), however now I'm in the middle of creating a colour class.

What I'm trying to do is a colour class, and then subtypes rgb,hsl,hsv and so on... my problem is when I make these variables how do I make it so when I read their value they appear as a uint?

for example I want to be able to do this.

var myRGBcolour:RGB = new RGB(14,21,42);
someSprite.graphics.beginFill(myRGBcolour);     //for those of you who don't know,
                                                //this function expects a uint

How can I achieve this? I was reading earlier about valueof functions but from what I can understand, you can only use that if you say something like myRGBcolour.valueOf() but that defeats the entire purpose, I might as well just make a myRGBcolour.toUint() function.

开发者_Python百科Thank's in advance.


you can try to override valueOf and make specific cast:

someSprite.graphics.beginFill(0+myRGBcolour); // 0+ is similar to 0x

or if you prefer:

someSprite.graphics.beginFill(myRGBcolour+0);

This construction is used in Fingers


beginFill() takes a uint, so you gotta give it one. I think having a toUint method sounds like the best plan, or having a get property.

0

精彩评论

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