带有动作脚本VPAID的SoundTransform

时间:2014-03-24 21:45:37

标签: actionscript-3 flash actionscript adobe

我对actionscript 3有疑问

我在VPAID做表演。 我无法创建方法adVolume。 我有编译错误

  

1067:将SoundTransform类型的值隐式强制转换为不相关的类型flash.media:SoundTransform。

     

1119:通过静态类型SoundTransform的引用访问可能未定义的属性卷。

这是一个功能adVolume

import flash.display.*;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.display.MovieClip;
import flash.media.Video;
import flash.events.*;
import flash.net.*;
import flash.media.SoundTransform;

public class FakeAd extends Sprite
{

    private var tw:twitter;
    private var fb:facebook;
    private var im:images;       
    public var nc:NetConnection;
    public var ns:NetStream;
    private var video:Video;
     private var adSoundTransform:SoundTransform;



    public function FakeAd(lineColor:Number, fillColor:Number, label:String)
    {


        function asyncErrorHandler(event:AsyncErrorEvent):void
        {

        }
        nc = new NetConnection();
        nc.connect(null);
        ns = new NetStream(nc);
        //ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, this.asyncErrorHandler);
        ns.play("http://traffic.idmnet.pl/21057/lekarzeIV.mp4");
        video = new Video(640,360);
        video.attachNetStream(ns);
        video.smoothing = true;
        addChild(video);
        ns.resume();

                    fb = new facebook();
        this.addChild(fb);
        //fb.x = 380;
        fb.y = 10;

        tw = new twitter();
        this.addChild(tw);
        //tw.x = 80;
        tw.y = 40;

        im = new images();
        this.addChild(im);
        im.y = 60;

        fb.addEventListener(MouseEvent.CLICK, facebookClicke);
        tw.addEventListener(MouseEvent.CLICK, twitterClicke);
        function facebookClicke(e:MouseEvent):void
        {
            navigateToURL(new URLRequest("https://pl-pl.facebook.com/"));
        }
        function twitterClicke(e:MouseEvent):void
        {
            navigateToURL(new URLRequest("https://twitter.com/"));
        }


        this.tw.x =   40;
        this.fb.x =   40;
        this.im.x =   40;
        this.tw.y =  150;


    }

    private function asyncErrorHandler(event:AsyncErrorEvent) : void
    {
        return;
    }

    public function iPause() : void
    {
        this.ns.pause();
        return;
    }

    public function iResume() : void
    {
        ns.resume();
        return;
    }

    public function  adVolume(value:Number) : void
    {
        adSoundTransform.volume = value;
        ns.soundTransform = adSoundTransform;
        return;
    }// end function



    }

和ExampleVPAID类

import flash.display.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.system.Security;
import flash.utils.Timer;

public class ExampleVPAID extends Sprite implements IVPAID {

    protected var timer:Timer;
    protected var adDuration:Number;
    protected var timeRemaining:Number;
    protected var initWidth:Number;
    protected var initHeight:Number;
    private var viewMode:String;
    private var fakeAd:FakeAd;
    protected var isLinearAd:Boolean = true;
    private static const VPAID_VERSION:String = "1.0"; 


    public function ExampleVPAID() {                  
        Security.allowDomain("*"); 
        mouseEnabled = false;    
        return;
    }// end function

    public function getVPAID():Object {
        return this;
    }//end function

    public function get adLinear():Boolean {            
        return isLinearAd;            
    }//end function

    public function get adExpanded():Boolean {
        return false;            
    }//end function

    public function get adRemainingTime():Number {
        return timeRemaining;            
    }//end function

    public function get adVolume():Number {
        return -1;
    }//end function

    public function set adVolume(value:Number):void {

    }// end function



    public function handshakeVersion(playerVPAIDVersion:String):String {
        log("The player supports VPAID version " + playerVPAIDVersion + " and the ad supports " + 
            VPAID_VERSION);
        return VPAID_VERSION;
    }

    protected function log(mesg:String):void {
        var data:Object = { "message":mesg };
        dispatchEvent(new VPAIDEvent(VPAIDEvent.AdLog, data));            
    }

    public function initAd(initWidth:Number, initHeight:Number, viewMode:String, desiredBitrate:Number, 
        creativeData:String, environmentVars:String):void {
        resizeAd(initWidth, initHeight, viewMode);
        loadAd();
    }

    private function getDurationValue(creativeData:String):void {
        var startIndex:Number = creativeData.indexOf("duration=");
        var endIndex:Number = creativeData.indexOf(";");
        adDuration = Number(creativeData.substring(startIndex + 9, endIndex));
    }

    protected function loadAd():void {
        dispatchEvent(new VPAIDEvent(VPAIDEvent.AdLoaded));
    }

    public function startAd():void {
        log("Beginning the display of the example VPAID ad");
        fakeAd = new FakeAd(0x4DB3B1, 0x38470B," I'm a VPAID Ad!");
        fakeAd.mouseEnabled = true;
        fakeAd.addEventListener(MouseEvent.CLICK, onAdClick);
        positionFakeAd();
        addChild(fakeAd);       
        dispatchEvent(new VPAIDEvent(VPAIDEvent.AdStarted));
        dispatchEvent(new VPAIDEvent(VPAIDEvent.AdImpression));
        adDuration = 15;
        timer = new Timer(1000, adDuration);
        timer.addEventListener(TimerEvent.TIMER, onTimer);
        timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerComplete);
        timer.start();            
    }

    protected function onTimer(pEvent:TimerEvent):void {
        timeRemaining--;
    }

    protected function onAdClick(event:MouseEvent):void {
        var data:Object = { "playerHandles":true };
        dispatchEvent(new VPAIDEvent(VPAIDEvent.AdClickThru, data));            
    }

    protected function timerComplete(event:Event):void {
        stopAd();
    }        

    public function stopAd():void {
        log("Stopping the display of the VPAID Ad");
        if (timer) {
            timer.removeEventListener(TimerEvent.TIMER, onTimer);
            timer.removeEventListener(TimerEvent.TIMER_COMPLETE, timerComplete);
            timer = null;
        }
        if (fakeAd) {
            removeChild(fakeAd);
            fakeAd = null;
        }
        dispatchEvent(new VPAIDEvent(VPAIDEvent.AdStopped));
    }

    public function resizeAd(width:Number, height:Number, viewMode:String):void {           
        this.initWidth = width;
        this.initHeight = height;
        this.viewMode = viewMode;
        positionFakeAd();
    }
    protected function positionFakeAd():void {
        if (fakeAd) {
            var widthAndHeight:Number = Math.min(initHeight, initWidth);
            var scale:Number=0;
            if (initWidth/fakeAd.width>initHeight/ fakeAd.height)
                scale=initHeight/ fakeAd.height;
                else scale=initWidth/fakeAd.width;

            fakeAd.x =0;
            fakeAd.y =0;
        }
    }

    public function pauseAd():void {
        if (timer) {
            timer.stop();
        }
        if(this.fakeAd)
        {
            this.fakeAd.iPause()
        }
        return;
    }

    public function resumeAd():void {
        if (timer) {
            timer.start();
        }
    }

    public function expandAd():void {
    }

    public function collapseAd():void {            
    }        
}

和VPAIDEvent

package

{     import flash.events.Event;

/*
 * VPAID events that a VPAID SWF can dispatch.  This class does not need to be used for any VPAID SWFs, 
 * but it can help make coding easier.  This source can be found in the VPAID specification: 
 * http://www.iab.net/media/file/VPAIDFINAL51109.pdf
 */
public class VPAIDEvent extends Event
{
    public static const AdLoaded:String = "AdLoaded";
    public static const AdStarted:String = "AdStarted";
    public static const AdStopped:String = "AdStopped";
    public static const AdLinearChange:String = "AdLinearChange";
    public static const AdExpandedChange:String = "AdExpandedChange";
    public static const AdRemainingTimeChange:String= "AdRemainingTimeChange";
    public static const AdVolumeChange:String = "AdVolumeChange";
    public static const AdImpression:String = "AdImpression";
    public static const AdVideoStart:String = "AdVideoStart";
    public static const AdVideoFirstQuartile:String= "AdVideoFirstQuartile";
    public static const AdVideoMidpoint:String = "AdVideoMidpoint";
    public static const AdVideoThirdQuartile:String= "AdVideoThirdQuartile";
    public static const AdVideoComplete:String = "AdVideoComplete";
    public static const AdClickThru:String = "AdClickThru";
    public static const AdUserAcceptInvitation:String= "AdUserAcceptInvitation";
    public static const AdUserMinimize:String = "AdUserMinimize";
    public static const AdUserClose:String = "AdUserClose";
    public static const AdPaused:String = "AdPaused";
    public static const AdPlaying:String = "AdPlaying";
    public static const AdLog:String = "AdLog";
    public static const AdError:String = "AdError";

    private var _data:Object;

    public function VPAIDEvent(type:String, data:Object=null, bubbles:Boolean=false,
        cancelable:Boolean=false) {
        super(type, bubbles, cancelable);
        _data = data;
    }

    public function get data():Object {
        return _data;
    }
}

}

请帮帮我

2 个答案:

答案 0 :(得分:0)

首先要尝试的是实例化变量' adSoundTransform'在做任何事情之前。编写的代码,您引用的是类,而不是类的实例。

    adSoundTransform = new SoundTransform();
    adSoundTransform.volume = value;
    ...

答案 1 :(得分:0)

另一件事是你应该解释来自VPAID的音量,例如:从"设置adVolume"传递它到你的FakeAd课程。广告不应该设置自己的音量,因为播放器应该处于控制之中。