1

我正在使用 Flash Pro CS6。我已经建立了一个通过 XML 注入 htmltext 的滚动文本字段。

我遇到的问题是 maxScrollV 似乎没有考虑到我的 images 。我试图在 html 中设置尺寸,<img src='assets/images/test.png' height='330' width='330' />但这似乎抛弃了自动换行。

public class ScrollingTextField extends Sprite
{
    private var myText:TextField;
    private var myFormat:TextFormat;
    private var bounds:Rectangle;
    private var boundHeight:Number;
    private var slider:SliderImage;

    public function ScrollingTextField()
    {
        trace("ScrollingTextField added");
        myText = new TextField();
        myFormat = new TextFormat();
        slider = new SliderImage();

        myFormat.font = "Arial";
        myFormat.color = 0x333333;
        myFormat.size = 14;
        addChild(myText);

        myText.htmlText = "init";
        myText.setTextFormat(myFormat);
        myText.wordWrap = true;
        myText.multiline = true;
        myText.setTextFormat(myFormat);
        myText.selectable = false;

        this.addChild(slider);

        slider.addEventListener(MouseEvent.MOUSE_DOWN, dragSlider);
        addEventListener(Event.ENTER_FRAME, checkSlider);
    }

    private function dragSlider(evt:MouseEvent):void
    {
        slider.startDrag();
        slider.removeEventListener(MouseEvent.MOUSE_DOWN, dragSlider);
        slider.addEventListener(MouseEvent.MOUSE_UP, dropSlider);
        addEventListener(MouseEvent.MOUSE_MOVE,moveSlider);
    }

    private function dropSlider(evt:MouseEvent):void
    {
        slider.stopDrag();
        slider.removeEventListener(MouseEvent.MOUSE_UP, dropSlider);
        slider.addEventListener(MouseEvent.MOUSE_DOWN, dragSlider);
        removeEventListener(MouseEvent.MOUSE_MOVE,moveSlider);
    }

    private function moveSlider(evt:MouseEvent):void
    {
        evt.updateAfterEvent();
        if (evt.buttonDown)
        {
            slider.startDrag(false,bounds);
        }
        else
        {
            slider.stopDrag();
        }
    }

    private function checkSlider(evt:Event):void
    {
        myText.scrollV = ((slider.y - bounds.y)* (myText.maxScrollV)/boundHeight);
    }

    public function textToDisplay(txt:String):void
    {
        myText.htmlText = txt;
        myText.setTextFormat(myFormat);
    }

    public function setDimensions(w:Number, h:Number):void
    {
        boundHeight = h - slider.height;
        bounds = new Rectangle(w + 20,10,0,h - slider.height);
        slider.x = w + 20;
        slider.y = 10;
        myText.width = w;
        myText.height = h;
    }

    public function checkTextFieldSize():void
    {
        trace("numLines = " + myText.numLines);
        trace("text height = " + myText.textHeight);
        trace("height = " + myText.height);
        if (myText.textHeight < myText.height)
        {
            slider.visible = false;
        }
        else
        {
            slider.visible = true;
        }
    }

}

}

4

1 回答 1

0

好吧,我最终做了一个便宜的解决方法。从网上搜索,似乎 .maxScrollV 只是不喜欢 .htmltext。我会把它带到 Adob​​e ......同时在<p>&nbsp;</p>html 中添加大量时间来充当图像空间,似乎可以解决问题。

于 2013-01-23T15:40:00.440 回答