Alpha 不适用于文本(flash、as3)

发布于 2024-12-09 12:04:51 字数 3349 浏览 1 评论 0原文

我想用“alpha”产生效果,但是当我使用特定的类在文本上设置滚动条时,文本不会响应我的 alpha。 您将看到文本不会响应补间开头的 alpha 0。

我正在使用在互联网上找到的一个很好的滚动条类,但我无法解释为什么会发生这种情况。

这是我在 fla 中的代码,它导入另一个类,该类导入滚动条类;-):

import com.greensock.*;
import com.greensock.easing.*;

var loader:Loader = new Loader;
var url:URLRequest = new URLRequest("Rhizo.swf");
loader.load(url);

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ec);

function ec (e:Event){
    var a = e.target.content;

    a.alpha = 0;
    addChild(e.target.content);
    TweenLite.to(a, 3, { x:30, alpha:1});

}

文档类,与包含上面代码的 fla 链接,我在其中调用滚动条类:

public class ScrollBarAS3 extends MovieClip {
        public var my_scrollbar:MakeScrollBar;

        public function ScrollBarAS3() {
            my_scrollbar = new MakeScrollBar( scroll_mc, scroll_text );
            scroll_txt.selectable = true; 
        }

        public function scroll_text( n:Number ) {
            scroll_txt.scrollV = Math.round( ( scroll_txt.maxScrollV - 1 ) * n ) + 1;
        }

这是滚动条类:

package {
    import flash.display.Stage;
    import flash.display.MovieClip;
    import flash.events.*;
    import flash.geom.Rectangle;

    public class MakeScrollBar extends MovieClip {
        private var host_mc:MovieClip;
        private var call_back:Function;

        private var drag_mc:MovieClip;
        private var track_mc:MovieClip;

        private var scroll_rect:Rectangle;
        private var upper_limit:Number;
        private var range:Number;

        public function MakeScrollBar( _mc:MovieClip, cb:Function ) {
            host_mc = _mc;
            call_back = cb;

            drag_mc = host_mc.drag_mc; // 
            drag_mc.buttonMode = true;
            drag_mc.mouseChildren = false
            drag_mc.addEventListener( MouseEvent.MOUSE_DOWN, press_drag );
            track_mc = host_mc.track_mc;
            track_mc.buttonMode = true;
            track_mc.mouseChildren = false
            track_mc.addEventListener( MouseEvent.CLICK, click_track );

            set_limits();
        }

        private function press_drag( event:MouseEvent ):void {
            /***************************************************/
            drag_mc.stage.addEventListener( MouseEvent.MOUSE_UP, release_drag, false, 0, true );
            /***************************************************/ 
            drag_mc.startDrag( false, scroll_rect );
            drag_mc.addEventListener( Event.ENTER_FRAME, drag );
        }

        private function release_drag( event:MouseEvent ):void {
            drag_mc.removeEventListener( Event.ENTER_FRAME, drag );
            drag_mc.stage.removeEventListener( MouseEvent.MOUSE_UP, release_drag );
            drag_mc.stopDrag();
        }

        private function click_track( event:MouseEvent ):void {
        }

        private function set_limits():void {
            scroll_rect = new Rectangle( track_mc.x, track_mc.y, 0, track_mc.height - drag_mc.height );
            upper_limit = track_mc.y;
            range = track_mc.height - drag_mc.height;
        }

        private function drag( event:Event ):void {
            var p = ( drag_mc.y - track_mc.y ) / range;
            call_back( p );
        }
    }
}

你知道吗?知道我能做些什么来让 alpha 工作吗?

非常感谢

干杯

i'd like to make an effect with "alpha", but when i'm using a particular class to set the scrollbar on my text, the text does not respond to my alpha.
You'll see that the text does not respond to the alpha 0 at the beginning of the tween.

I'm using a good scrollbar class that i found on internet, but i can't explain why this is happening.

Here's my code in the fla that imports another class, which imports the scrollbar class ;-) :

import com.greensock.*;
import com.greensock.easing.*;

var loader:Loader = new Loader;
var url:URLRequest = new URLRequest("Rhizo.swf");
loader.load(url);

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ec);

function ec (e:Event){
    var a = e.target.content;

    a.alpha = 0;
    addChild(e.target.content);
    TweenLite.to(a, 3, { x:30, alpha:1});

}

the document class, linked with the fla that contains the code above, where i call the scroll bar class :

public class ScrollBarAS3 extends MovieClip {
        public var my_scrollbar:MakeScrollBar;

        public function ScrollBarAS3() {
            my_scrollbar = new MakeScrollBar( scroll_mc, scroll_text );
            scroll_txt.selectable = true; 
        }

        public function scroll_text( n:Number ) {
            scroll_txt.scrollV = Math.round( ( scroll_txt.maxScrollV - 1 ) * n ) + 1;
        }

and here's the scrollbar class :

package {
    import flash.display.Stage;
    import flash.display.MovieClip;
    import flash.events.*;
    import flash.geom.Rectangle;

    public class MakeScrollBar extends MovieClip {
        private var host_mc:MovieClip;
        private var call_back:Function;

        private var drag_mc:MovieClip;
        private var track_mc:MovieClip;

        private var scroll_rect:Rectangle;
        private var upper_limit:Number;
        private var range:Number;

        public function MakeScrollBar( _mc:MovieClip, cb:Function ) {
            host_mc = _mc;
            call_back = cb;

            drag_mc = host_mc.drag_mc; // 
            drag_mc.buttonMode = true;
            drag_mc.mouseChildren = false
            drag_mc.addEventListener( MouseEvent.MOUSE_DOWN, press_drag );
            track_mc = host_mc.track_mc;
            track_mc.buttonMode = true;
            track_mc.mouseChildren = false
            track_mc.addEventListener( MouseEvent.CLICK, click_track );

            set_limits();
        }

        private function press_drag( event:MouseEvent ):void {
            /***************************************************/
            drag_mc.stage.addEventListener( MouseEvent.MOUSE_UP, release_drag, false, 0, true );
            /***************************************************/ 
            drag_mc.startDrag( false, scroll_rect );
            drag_mc.addEventListener( Event.ENTER_FRAME, drag );
        }

        private function release_drag( event:MouseEvent ):void {
            drag_mc.removeEventListener( Event.ENTER_FRAME, drag );
            drag_mc.stage.removeEventListener( MouseEvent.MOUSE_UP, release_drag );
            drag_mc.stopDrag();
        }

        private function click_track( event:MouseEvent ):void {
        }

        private function set_limits():void {
            scroll_rect = new Rectangle( track_mc.x, track_mc.y, 0, track_mc.height - drag_mc.height );
            upper_limit = track_mc.y;
            range = track_mc.height - drag_mc.height;
        }

        private function drag( event:Event ):void {
            var p = ( drag_mc.y - track_mc.y ) / range;
            call_back( p );
        }
    }
}

Do you know what i could do to make the alpha work?

Thanks a lot

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昔梦 2024-12-16 12:04:51

从 AS3 的角度来看,除非将 TextField 的 embedFonts 属性设置为 true,否则您将无法将透明度应用于 TextField。我建议问题出在加载的 SWF 上,但您没有为其提供任何代码...

//------------------------ 编辑---------------------//

如果你简单地这样做会发生什么?文字出现吗?

function ec (e:Event){
    var a = e.target.content;

    a.alpha = 0;
    addChild(e.target.content);

}

您在本地测试了 .swf 吗?
您是否尝试过在不使用 ScrollBar 的情况下简单地加载影片并设法使 alpha 正常工作?
目前,我在 ScrollBar 类中没有看到任何可能干扰文本透明度的内容......

From an AS3 point of view , you will not be able to apply transparency to a TextField unless its embedFonts property is set to true. I would suggest that the problem is with the loaded SWF but you don't provide any code for it...

//----------------------- Edit ---------------------//

What happens if you simply do this? Does the text appear?

function ec (e:Event){
    var a = e.target.content;

    a.alpha = 0;
    addChild(e.target.content);

}

Did you test the .swf locally?
Have you tried to simply load the movie, without the ScrollBar and managed to get the alpha working?
At the moment, I don't see anything in the ScrollBar class that could interfere with the text transparency...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文