1

有什么方法可以在加载 SWF 时自动单击 XY 舞台坐标?

编辑:顺便说一句,这是整个代码,它是一个提示的 youtube 视频。只需在 SWF 加载后单击提示上的任意位置即可自动播放。

Security.allowDomain("www.youtube.com");


var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));

function onLoaderInit(event:Event):void {
    addChild(loader);
    loader.content.addEventListener("onReady", onPlayerReady);
    loader.content.addEventListener("onError", onPlayerError);
    loader.content.addEventListener("onStateChange", onPlayerStateChange);
    loader.content.addEventListener("onPlaybackQualityChange", 
        onVideoPlaybackQualityChange);
}

function onPlayerReady(event:Event):void {

    trace("player ready:", Object(event).data);


    player = loader.content;

    player.setSize(300, 250);
    player.cueVideoById("AfTCtRDsWVw",0);
    player.mute();
}



function onPlayerError(event:Event):void {
    trace("player error:", Object(event).data);
}

function onPlayerStateChange(event:Event):void {
    trace("player state:", Object(event).data);
}

function onVideoPlaybackQualityChange(event:Event):void {
    trace("video quality:", Object(event).data);
}
4

3 回答 3

3

是的,您应该手动将 MouseEvent.CLICK 事件发送到您的舞台:

var yourX:Number = 40; //Whatever you want
var yourY:Number = 40; //Whatever you want
//Make sure you have a link to the stage (usually after Event.ADDED_TO_STAGE event occured)
stage.dispatchEvent(new MouseEvent(
    MouseEvent.CLICK, 
    true, 
    false, 
    yourX,
    yourY);

如果您需要某个 DisplayObject 与此 MouseEvent 相关联,则应向 MouseEvent 构造函数传递一个附加参数:

var yourX:Number = 40; //Whatever you want
var yourY:Number = 40; //Whatever you want
//Make sure you have a link to the stage (usually after Event.ADDED_TO_STAGE event occured)
stage.dispatchEvent(new MouseEvent(
    MouseEvent.CLICK, 
    true, 
    false, 
    yourX,
    yourY,
    linkToYourRelatedDisplayObject);

==更新==

嗯,我成功了。有点“黑客”,就在这里。您的 youtube 播放器包含一个 safeLoader 对象,该对象包含一个 videoApplication,其中包含一个 LargePlayerButton。这个 LargePlayerButton 有一个 MouseEvent.CLICK 事件监听器,所以我们需要将事件分派给这个按钮,而不是分派给舞台。这是带有 autoClick 模拟的完整代码:

import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.DisplayObjectContainer;

// The player SWF file on www.youtube.com needs to communicate with your host
// SWF file. Your code must call Security.allowDomain() to allow this
// communication.
Security.allowDomain("www.youtube.com");

// This will hold the API player instance once it is initialized.
var player:Object;

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));

function onLoaderInit(event:Event):void {
    addChild(loader);
    loader.content.addEventListener("onReady", onPlayerReady);
}

function autoClick():void
{
    //=========================
    //Some nested children, we need to dig through a bit to get to the LargePlayButton
    var safeLoader:DisplayObjectContainer = (loader.content as DisplayObjectContainer).getChildAt(0) as DisplayObjectContainer;
    var videoApplication:DisplayObjectContainer = safeLoader.getChildAt(0) as DisplayObjectContainer;
    var largePlayBtn:DisplayObjectContainer = videoApplication.getChildAt(6) as DisplayObjectContainer; 
    //=========================
    //And finally dispatching our event to this button. It will think that a person has clicked it
    largePlayBtn.dispatchEvent(new MouseEvent(MouseEvent.CLICK, 
                                       true, 
                                       true, 
                                       stage.stageWidth / 2,
                                       stage.stageHeight / 2));

}

function onPlayerReady(event:Event):void {
    // Event.data contains the event parameter, which is the Player API ID 
    trace("player ready:", Object(event).data);

    // Once this event has been dispatched by the player, we can use
    // cueVideoById, loadVideoById, cueVideoByUrl and loadVideoByUrl
    // to load a particular YouTube video.
    player = loader.content;
    // Set appropriate player dimensions for your application
    player.setSize(300, 250);
    player.cueVideoById("AfTCtRDsWVw",0);
    //====================================================
    //As long as player is loaded we can call our function
    autoClick();
}

这是一个很好的练习,干杯:)

于 2013-08-31T08:45:26.573 回答
0

Youtube 似乎有一个智能的反黑客功能。我可以在 IDE 上获取 SafeLoader 的子级,但在 Flash 播放器或 Web 上,SafeLoader 无法访问,之后无法控制任何子级。这就是为什么代码可以在 IDE 上运行但不能在外部运行的原因。也许它与沙盒安全有关,但也许它更复杂。

于 2013-11-17T13:10:05.093 回答
-1

出于明显的安全原因,我非常怀疑这是可能的:http: //www.adobe.com/devnet/flashplayer/articles/fplayer10_uia_requirements.html

于 2013-08-31T14:44:48.117 回答