如何退出从ActionScript库AIR应用程序? [英] How to exit an air application from an actionscript library?

查看:114
本文介绍了如何退出从ActionScript库AIR应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试以下,但每一个曾经在一段时间的nativeApp没有定义。

I am trying the following but every once in awhile the nativeApp is not defined.

var nativeApp:Object =  getDefinitionByName("flash.desktop.NativeApplication");
nativeApp.nativeApplication.exit();

我很困惑,为什么有时getDefinitionByName(flash.desktop.NativeApplication在)做出决议​​和其他时候也不能。

I am confused why sometimes getDefinitionByName("flash.desktop.NativeApplication") resolves and other times it does not.

我想解决这个问题,以对Flexcover中解决以下问题 - ?code.google.com / P /对Flexcover /问题/细节ID = 33

I am trying to resolve this problem to address the following issue in flexcover - code.google.com/p/flexcover/issues/detail?id=33

更新 - 这里是一流的,我尝试修复:<一href="http://$c$c.google.com/p/flexcover/source/browse/trunk/CoverageAgent/src/com/allurent/coverage/runtime/AbstractCoverageAgent.as" rel="nofollow">http://$c$c.google.com/p/flexcover/source/browse/trunk/CoverageAgent/src/com/allurent/coverage/runtime/AbstractCoverageAgent.as CoverageAgent.swc是一个ActionScript库调用的单元测试,退出来确定单元测试的code覆盖的空气对Flexcover应用。对Flexcover的AIR应用程序只能退出对一半的时间,这导致我​​们的行家问题建立成功执行。

Update - here is the class I am attempting to fix: http://code.google.com/p/flexcover/source/browse/trunk/CoverageAgent/src/com/allurent/coverage/runtime/AbstractCoverageAgent.as CoverageAgent.swc is an actionscript library called by the unit tests to exit the flexcover air application used to determine the code coverage of the unit tests. The flexcover air application only exits about the half the time and it is causing problems for our maven builds to execute successfully.

推荐答案

在关于对Flexcover - 的原因,你看到它的工作有时而不是其他人是CoverageAgent旨在退出单元测试并不反馈给CoverageViewer。我已经创建了自己的FlexCoverListener发送退出消息移交给CoverageViewer本地连接。下面是code。

In regards to FlexCover - the reason you are seeing it work sometimes and not others is the CoverageAgent is designed to exit the Unit Tests it does not communicate back to the CoverageViewer. I have created my own FlexCoverListener that sends an exit message over local connection to the CoverageViewer. Below is the code.

package org.flexunit.listeners
{
import flash.events.EventDispatcher;

import org.flexunit.listeners.closer.FlexCoverCloser;
import org.flexunit.runner.IDescription;
import org.flexunit.runner.Result;
import org.flexunit.runner.notification.Failure;
import org.flexunit.runner.notification.IAsyncStartupRunListener;
import org.flexunit.runner.notification.ITemporalRunListener;

public class FlexCoverListener extends EventDispatcher implements IAsyncStartupRunListener,    
ITemporalRunListener
{
  import com.allurent.coverage.runtime.CoverageManager;

  public function FlexCoverListener()
  {
  }

  public function get ready():Boolean 
  {
      return true;
  }

  public function testTimed( description:IDescription, runTime:Number ):void
  {

  }


  public function testRunFinished( result:Result ):void 
  {
      CoverageManager.agent.recordCoverage("SR_TESTS_COMPLETE");
  }

  public function testFinished( description:IDescription ):void {}

  public function testRunStarted( description:IDescription ):void {}


  public function testStarted( description:IDescription ):void{}


  public  function testFailure( failure:Failure ):void{}


  public function testAssumptionFailure( failure:Failure ):void{}


  public function testIgnored( description:IDescription ):void{}
  }
  }

您可以通过执行以下操作在你的TestRunner添加上面监听到你的测试:

You can add the above listener to your tests by doing the following in your TestRunner:

core.addListener(new FlexCoverListener());
var core : FlexUnitCore = new FlexUnitCore();

最后,但最重要的是我改变了 AbstractCoverageAgent 看起来像下面的 recordCoverage 方法:

Last but most importantly I changed the recordCoverage method in the AbstractCoverageAgent to look like the following:

/**
     * Record the execution of a single coverage key; called by
     * the global coverage() function.
     */
    public function recordCoverage(key:String):void
    {
        if(key == "SR_TESTS_COMPLETE")
        {
            exit();    
        }
        else if (isNaN(coverageMap[key]++))
        {
            // The map must not have contained this key yet, so enter an
            // execution count of 1.  Subsequent calls will autoincrement without
            // returning NaN.
            //
            coverageMap[key] = 1;
        }
    }

这篇关于如何退出从ActionScript库AIR应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆