0
votes

I have a problem with actionscript 3

I am doing performances in VPAID. I can not create a method adVolume. I have a compile error

1067: Implicit coercion of a value of type SoundTransform to an unrelated type flash.media:SoundTransform.

1119: Access of possibly undefined property volume through a reference with static type SoundTransform.

This is a function 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



    }

And ExampleVPAID class

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 {            
    }        
}

And 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;
    }
}

}

Please Help me

2

2 Answers

0
votes

First thing to try is to instantiate your variable 'adSoundTransform' before doing anything with it. Code as written, you are referencing the class, not an instance of the class.

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

One other thing is that you should be interpreting the volume coming from VPAID, e.g. passing it along from "set adVolume" to your FakeAd class. Ads should never be setting their own volume, since the player should be in control.