bukowski
bukowski

Reputation: 1943

Get the domain where flash swf file is being played

So I want to get the domain where the flash swf is being played and not the location of the file. If only I could get ExternalInterface to return the value like so:

var domain:String = ExternalInterface.call("document.domain");

But the above produces null.... Its an banner ad so I can't pass any flashvars to it or call custom js functions

Upvotes: 1

Views: 166

Answers (1)

Teejay
Teejay

Reputation: 7471

It returns null because you're not calling nothing:

document.domain is the name of a variable, not a method call.

Try return document.domain instead.

EDIT:

The correct syntax is to create an anonymous function that returns the document's domain:

import flash.external.ExternalInterface;

var domain:String = "";

if (ExternalInterface.available == true)
{
    try
    {
       domain = ExternalInterface.call("function() { return document.domain; }");
    }
    catch (err:Error)
    {
       domain = "Error: " + err.message;
    }

    if (domain == null) domain = "No domain"
}

Upvotes: 2

Related Questions