【问题标题】:AS3 - using dynamic Text as a maskAS3 - 使用动态文本作为掩码
【发布时间】:2017-09-03 20:55:49
【问题描述】:

很确定这是可能的。我需要动态加载和填充一个文本字段,然后将该文本用作其下方影片剪辑的蒙版。我有

function doMask():void{
    myMc.dynamicTxtField.text = "some text to use as a mask";
    mcToBeMasked.mask = myMc;
}

doMask();

发生的情况是整个文本字段被用作掩码,而不仅仅是它包含的文本。

【问题讨论】:

  • 你试过mcToBeMasked.mask=myMc.dynamicTxtField吗?
  • myMc里面还有其他东西吗?上述推荐应该有效。 (将掩码设置为文本字段对象本身。)
  • 我测试了它。如果我将 flashPro 文本字段拖到舞台上并将其用作掩码,它就可以工作。但是,如果我只通过代码创建了一个 textField,它就不起作用了。需要进一步调查,但我目前没有时间。 @eco_back - 你使用的是通过代码创建的 textField 吗?
  • 你可以这样做,但前提是你使用嵌入的字体,当然,如果 TextField 没有背景。在这种情况下,您不需要使用 cacheAsBitmap。

标签: actionscript-3 flash text mask


【解决方案1】:

我不确定如何将动态文本用作蒙版,但您可以使用混合模式获得类似的效果。例如将图像与黑色背景上的动态文本相乘。

【讨论】:

  • 考虑通过添加代码示例使您的答案更有用。否则,这是一个非常低质量的答案。
  • 感谢您的反馈,但我只能编写伪代码。我已经 4 年没有写过 AS3,但我仍然了解混合模式的工作原理。
【解决方案2】:

在设置掩码之前将其添加到两者。

myMc.dynamicTxtField.cacheAsBitmap = true;
mcToBeMasked.cacheAsBitmap = true;

【讨论】:

    【解决方案3】:

    这可以使用 [BlendMode][1] 来实现,如下所示(建议here):

        container.blendMode = BlendMode.LAYER;//parent of toMask and textfield
        toMask.blendMode = BlendMode.NORMAL;//sprite to be masked
        tf.blendMode = BlendMode.ALPHA;//masking textfield
    

    a working example on wonderfl:

    package {
        import flash.text.TextFormat;
        import flash.display.Bitmap;
        import flash.display.BitmapData;
        import flash.text.TextField;
        import flash.display.Sprite;
        import flash.display.BlendMode;
        import flash.events.MouseEvent;
        public class FlashTest extends Sprite {
            private var tf:TextField = new TextField();
            private var container:Sprite = new Sprite();
            private var toMask:Sprite = new Sprite();
            private const WIDTH:int = 250;
            private const HEIGHT:int = 150;
            public function FlashTest() {
                graphics.beginFill(0x0000ff);
                graphics.drawRect(0, 0, 300, 300);
                graphics.endFill();       
    
                addChild(container);     
                tf.defaultTextFormat = new TextFormat(null, 15, 0, true);
                tf.text = 'sample text';
                tf.cacheAsBitmap = true;
                container.blendMode = BlendMode.LAYER;
                toMask.blendMode = BlendMode.NORMAL;
                tf.blendMode = BlendMode.ALPHA;
                container.addChild(toMask);
                container.addChild(tf);
                toMask.graphics.beginFill(0x00ff00);
                toMask.graphics.drawRect(0, 0, WIDTH, HEIGHT);
                toMask.graphics.endFill();
                tf.width = WIDTH;
                tf.height = HEIGHT;
                stage.addEventListener(MouseEvent.CLICK, onClick);
            }
    
            private function onClick(e:MouseEvent = null):void{
                tf.text = 'sample text ' + Math.random();
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-28
      相关资源
      最近更新 更多