辛夷坞

涧户寂无人,纷纷开且落

By - Christen

ActionScript Boolean 定义:AS 3.0 流量监测

现在 ActionScript 3.0 版本的广告素材越来越多,加流量监测的时候,一定要注意首次播放控制的写法,因为大多数广告还是基于时间轴的动画,默认会重复播放,如果按我们习惯的定义方法(比如 Java),Flash 重播的时候,会反复触发流量请求,最终导致过度曝光,后果严重。
我也不太确信,这算不算 Flash 的一个 Bug,反正陷阱应该算。
如果不是 Bug,难道 Flash 重播的时候,会重置变量?

保持关注。

会重复发起流量请求,导致过度曝光

测试地址:http://www.chenzixin.com/static/demo/impbug/test-1.html

import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.ui.Mouse;
import flash.ui.MouseCursor;
var tag:String = "http://v.admaster.com.cn/i/a12323,b200147754,c1350,i0,m201,h" + new Date().getTime();
var isControl:Boolean = true;
Mouse.cursor = MouseCursor.BUTTON;
try
{
    if (isControl)
    {
        new URLLoader().load(new URLRequest(tag));
        isControl = false;
    }
}
catch (error:Error)
{
    trace("unable to loader" + error);
}
stage.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(evt:MouseEvent):void
{
    var click_URL:String = "http://www.google.com/";
    navigateToURL(new URLRequest(click_URL));
}

下面这个写法是OK的

测试地址:http://www.chenzixin.com/static/demo/impbug/test-2.html

import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.ui.Mouse;
import flash.ui.MouseCursor;
var tag:String = "http://v.admaster.com.cn/i/a12323,b200147754,c1350,i0,m201,h" + new Date().getTime();
var isControl;
Mouse.cursor = MouseCursor.BUTTON;
try
{
    if (isControl == undefined)
    {
        new URLLoader().load(new URLRequest(tag));
        isControl = true;
    }
}
catch (error:Error)
{
    trace("unable to loader" + error);
}
stage.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(evt:MouseEvent):void
{
    var click_URL:String = "http://www.google.com/";
    navigateToURL(new URLRequest(click_URL));
}

但在基于定时器的动画里,这个Bug不会触发

测试地址:http://www.chenzixin.com/static/demo/impbug/test-3.html

import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.ui.Mouse;
import flash.ui.MouseCursor;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.external.ExternalInterface;
var tag:String = "http://v.admaster.com.cn/i/a12323,b200147754,c1350,i0,m201,h" + new Date().getTime();
var isControl:Boolean = true;
Mouse.cursor = MouseCursor.BUTTON;
function moveBox(evt:Event):void
{
    var myTween:Tween = new Tween(my_box,"x",Strong.easeOut,40,300,5,true);
}
var myTimer:Timer = new Timer(1500);
myTimer.addEventListener(TimerEvent.TIMER, moveBox);
myTimer.start();
try
{
    if (isControl)
    {
        new URLLoader().load(new URLRequest(tag));
        if (ExternalInterface.available)
        {
            ExternalInterface.call("printImp", tag);
        }
        isControl = false;
    }
}
catch (error:Error)
{
    trace("unable to loader" + error);
}
stage.addEventListener(MouseEvent.CLICK, clickHandler);
//stage.addEventListener(Event.ENTER_FRAME, moveBox);
function clickHandler(evt:MouseEvent):void
{
    var click_URL:String = "http://www.google.com/";
    navigateToURL(new URLRequest(click_URL));
}

HTML代码:

<div id="flashContent">
  <p>Alternative content</p>
</div>
<form name="form1" onsubmit="return false;">
  <textarea id="console" cols="80" rows="10" name="output" readonly="true"></textarea>
</form>

Javascript代码:

// https://code.google.com/p/swfobject/wiki/documentation
var flashvars = {
  name1: "hello",
  name2: "world",
  name3: "foobar"
};
var params = {
  menu: "false"
};
var attributes = {
  id: "myDynamicContent",
  name: "myDynamicContent"
};
swfobject.embedSWF("test-2.swf", "flashContent", "550", "90", "9.0.0","/assets/themes/christen/swfobject/expressInstall.swf", flashvars, params, attributes);
function printImp (value) {
  document.forms["form1"].output.value += "" + value + "n";
}

1 thought on “ActionScript Boolean 定义:AS 3.0 流量监测

陈自新 November 23, 2014 at 5:09 pm

Test if the comments are okey.

Reply

Leave a Reply

Your email address will not be published.
*
*