1. ActionScript / Говнокод #16464

    −153

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    private function getOldPreviewBySize(width: Number, height: Number): BitmapData
     			{
    -				return oldPreviewsArr[width.toString() + height.toString()];
    +				if (width && height)
    +					return oldPreviewsArr[width.toString() + height.toString()];
    +				else
    +					return null;
     			}

    хорошо исправил (размеры картинки вполне могут быть и двух и трех-значными цифрами)

    wvxvw, 03 Августа 2014

    Комментарии (105)
  2. ActionScript / Говнокод #16159

    −102

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    x = 1;
    					x = (x >> 11);
    					x = (x + 1);
    					x = (x >> 9);
    					x = (x + 1);
    					x = (x >> 7);
    					x = (x + 1);
    					x = (x >> 5);
    					x = (x + 1);
    					x = (x >> 3);
    					x = (x + 1);
    					x = (x >> 10);
    					x = (x + 1);
    					x = (x >> 8);
    					x = (x + 1);
    					x = (x >> 6);
    					x = (x + 1);
    					x = (x >> 4);
    					x = (x + 1);
    					x = (x >> 2);
    					x = (x + 1);
    					if (x == 1)
    					{
    						ge.ha = true;
    					};

    из недр не менее изощрённого распковщика обфусцированного xml

    makc3d, 13 Июня 2014

    Комментарии (5)
  3. ActionScript / Говнокод #16146

    −106

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    case EffectVO.ENTER_FROM_LEFT: 
    	xFrom = - (sprite.boundingRect.width + Math.abs(sprite.boundingRect.x));
    	xFrom *= extraSafetyScaleFactor;
    	objectTween = TweenLite.from(spriteView, 0.5,
            {
                x: String(xFrom),
                immediateRender: true,
                ease: Cubic.easeOut
            });

    Культовый код. Вот, недавно набрел на ссылку:
    http://en.wikipedia.org/wiki/Cargo_cult_programming
    Почему-то во всем проекте анимированые свойства либо конвертируются в строки, либо изначально задаются строками. Писец давно уволился, и выяснить первопричину сейчас не представляется возможным, но существует предположение, что таким образом писец боролся с NaN... вряд ли это конечно могло помочь, но на то он и культ.

    wvxvw, 11 Июня 2014

    Комментарии (1)
  4. ActionScript / Говнокод #15695

    −136

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    /**
     *  @private
     *  Calculates the height needed for heightInLines lines using the default
     *  font.
     */
    private function calculateHeightInLines():Number
    {
        var height:Number = getStyle("paddingTop") + getStyle("paddingBottom");
        
        if (_heightInLines == 0)
            return height;
        
        var effectiveHeightInLines:int;
        
        // If both height and width are NaN use 10 lines.  Otherwise if 
        // only height is NaN, use 1.
        if (isNaN(_heightInLines))
            effectiveHeightInLines = isNaN(_widthInChars) ? 10 : 1;   
        else
            effectiveHeightInLines = _heightInLines;
        
        // Position of the baseline of first line in the container.
        value = getStyle("firstBaselineOffset");
        if (value == lineHeight)
            height += lineHeight;
        else if (value is Number)
            height += Number(value);
        else
            height += ascent;
        
        // Distance from baseline to baseline.  Can be +/- number or 
        // or +/- percent (in form "120%") or "undefined".  
        if (effectiveHeightInLines > 1)
        {
            var value:Object = getStyle("lineHeight");     
            var lineHeight:Number =
                RichEditableText.getNumberOrPercentOf(value, getStyle("fontSize"));
            
            // Default is 120%
            if (isNaN(lineHeight))
                lineHeight = getStyle("fontSize") * 1.2;
            
            height += (effectiveHeightInLines - 1) * lineHeight;
        }            
        
        // Add in descent of last line.
        height += descent;              
        
        return height;
    }

    Внимательно следим за жизненным циклом переменной lineHeight.

    wvxvw, 07 Апреля 2014

    Комментарии (17)
  5. ActionScript / Говнокод #15621

    −131

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    protected function ignite(event:FlexEvent):void {
        imgCooser.dataProvider = new ArrayList([new ObjectProxy({w:Math.round(Math.random()*100+55),t:'0 one'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'1 two'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'2 three'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'3 four'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'4 five'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'5 six'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'6 seven'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'7 eight'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'8 nine'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'9 ten'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'10 eleven'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'11 twelve'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'12 one'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'13 two'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'14 three'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'2 three'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'3 four'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'4 five'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'5 six'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'6 seven'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'7 eight'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'8 nine'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'9 ten'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'10 eleven'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'11 twelve'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'12 one'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'13 two'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'14 three'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'1 two'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'2 three'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'3 four'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'4 five'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'5 six'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'6 seven'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'7 eight'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'8 nine'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'9 ten'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'10 eleven'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'11 twelve'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'12 one'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'13 two'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'14 three'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'2 three'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'3 four'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'4 five'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'5 six'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'6 seven'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'7 eight'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'8 nine'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'9 ten'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'10 eleven'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'11 twelve'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'12 one'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'13 two'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'14 three'}),
                   new ObjectProxy({w:Math.round(Math.random()*100+55),t:'15 four'})]);

    От нечего делать сижу и перебираю коммиты в репозитории, вот наткнулся...

    wvxvw, 30 Марта 2014

    Комментарии (1)
  6. ActionScript / Говнокод #15619

    −136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public function TweenMax(target:Object, duration:Number, vars:Object) {
    	super(target, duration, vars);
    	if (TweenLite.version < 11.2) {
    		throw new Error("TweenMax error! Please update your TweenLite class or try deleting your ASO files. TweenMax requires a more recent version. Download updates at http://www.TweenMax.com.");
    	}

    Тут нужно дополнительно подчеркнуть, что оба класса TweenMax и TweenLite распространяются вместе, и случайно получить несоответствующую версию очень тяжело (ее надо самому поменять).
    Но самое интересное в другом: ASO файлы - это артефакт механизма кеширования использовавшегося в AS2. В AS3 механизм кеширования другой, и об этих файлах давным-давно никто не слышал. Тем не менее, сообщение об ошибке по прежнему предлагает пользователям с ними побороться.

    wvxvw, 30 Марта 2014

    Комментарии (1)
  7. ActionScript / Говнокод #15534

    −123

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    private var _index:int;
    
    [XmlAttribute]
    [Bindable(event="indexChanged")]
    public function get index():int
    {
    	return deck.slides.getItemIndex(this) + 1;
    }
    
    public function set index(value:int):void
    {
    	_index = value;
    }
    
    private function getIndex(time:Number):int
    {
    	return MathAndGeometryUtils.roundToHalf(time) * 2;
    }
    
    private function getTime(index:int):Number
    {
    	return index / 2;
    }

    Эркюль Пуаро нервно набивает трубку табаком.

    wvxvw, 19 Марта 2014

    Комментарии (2)
  8. ActionScript / Говнокод #15403

    −123

    1. 1
    2. 2
    3. 3
    4. 4
    var player:c2Player = world.getPlayer();
    var block:c2Block = world.getBlock(player);
    
    player.x = (player.xpos - block.xpos)*(player.angle + block.angle * Math.cos(player.angle/180*Math.PI)*(10-10+1-1+0);

    Оригинальная и полезная формула.

    Bletraut, 09 Марта 2014

    Комментарии (28)
  9. ActionScript / Говнокод #14631

    −122

    1. 1
    ObjectUtils.deleteFromDictionary(showTweens,  slideView);

    Для тех, кто не в курсе:

    delete dictionary[key];

    wvxvw, 18 Февраля 2014

    Комментарии (1)
  10. ActionScript / Говнокод #14539

    −122

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    protected override function getCurrentSkinState():String
    {
    	if (!this._currentState) this._currentState = "edit";
    	else this._currentState = super.getCurrentSkinState() || "edit";
    	return this._currentState;
    }

    Еще грабли от Адоба.

    wvxvw, 11 Февраля 2014

    Комментарии (20)