Thursday, October 16, 2008
Wednesday, June 11, 2008
Picking up the domain name where your flash file/player has been hosted
This problem was bugging me for a long time and I was not able to find the solution until recently when I dug into few internet blogs again for sometime and was able to crack the problem.
Actually this was a request that came up to me last year for tracking the IPs or domain name where our flash application/player is blogged or embedded. The only solution then I was thinking of was _root._url. But that was of no use as the flash player was being picked from our website and it was returning the URL of our website then the website where it was embedded. I even thought of getURL but it was not useful in this solution. I never worked with
ExternalInterface much at that time and never thought it will be of any use as such for me as I thought its functionality is almost like getURL so it will be same as getURL.
So I never dug deep into ExternalInterface at that time and I just thought whenever we try to send some variable to through sendAndLoadVar to our domain for tracking the visit count why not try to read the request header. Maybe request header will have the domain information in http-referrer or somewhere. But when we tried to dig deep into that we found that it's the client ip information which we receive in the request header not the domain information so that solution was too ruled out.
This year again when I was approached for the solution I thought do some more search & research. I came across this blog of abdul qabiz; there in one thread I found some useful information and came across a mention of another website Flex Pasta". There I found the solution to my problem that I can use
ExternalInterface to get this domain information and many other information variables like port or URL parameters.
So here I found the solution. I created a small code snippet to test it and see how it’s working on a different domain; I created 2 text fields on stage in AS2 file:
So it worked locally for me. But when I hosted this file on one website and pasted embed code in one blog, I got null as the value in the textfield. Then I tried to look into the Adobe help docs; there I found that if any error occurred it will return null. So I just tried to do some checkup on the Internet and then I found that allowScriptAccess must always be set as always; then only it will return the value.
So I am again stuck in the middle! I will be able to return the track of only those blogs, which will allow me to embed the code with allowscriptaccess as always but due to security threats many of the major blogs have already changed it; they have set it's value as never so you can't embed any third party swf file into these blogs with allowscriptaccess tag with value other then never. So does that mean you can't get domain name track backs from these blogs? I tried to do try catch as you see in the above code but nothing was returned in AS2 other then null.
So I read one comment in the Abdul Qabiz blog that he got a security error back in try catch and in that string he got where it was occurred along with the swf file path. I tried that in ActionScript3/CS3 file something like this:
I mentioned the variable type of loc as "*" because I read a comment from senocular on Flashkit that the variable returned by ExternalInterface.call is of type "*". When I tried to assign that value to textfield it gave me an error: TypeError: Error #2007: Parameter text must be non-null. So there I have to typecast the variable as String to remove the error. Now when I published the file and tried that with 'allowscriptaccess' set to 'never' in embed code, I got a flash player error alert popup which said that the following swf can't access the following html file in which it is embedded.
Now as html page is hosted on the domain for which I was looking i.e. I can parse out the domain name from that error but an alert is not something a visitor likes to see. I put that call in try catch and got the error trace which has domain name in html page reference in catch block.
Similarly if you want to do it in Flex application you can do it something like:
Init method can be called up on creation complete event of application.
Another problem which I came across this whole process was that during my tracing I noticed that although I can trace up external interface call in Firefox and Safari but Internet Explorer was not responding to the call. When I dug upon it a bit I found on one of the forums that specifying the flash file id in Object tag is a must to make sure your ExternalInterface call go through and return you a value. For e.g.<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' width='481' height='402' id='player'>
Actually this was a request that came up to me last year for tracking the IPs or domain name where our flash application/player is blogged or embedded. The only solution then I was thinking of was _root._url. But that was of no use as the flash player was being picked from our website and it was returning the URL of our website then the website where it was embedded. I even thought of getURL but it was not useful in this solution. I never worked with
ExternalInterface much at that time and never thought it will be of any use as such for me as I thought its functionality is almost like getURL so it will be same as getURL.
So I never dug deep into ExternalInterface at that time and I just thought whenever we try to send some variable to through sendAndLoadVar to our domain for tracking the visit count why not try to read the request header. Maybe request header will have the domain information in http-referrer or somewhere. But when we tried to dig deep into that we found that it's the client ip information which we receive in the request header not the domain information so that solution was too ruled out.
This year again when I was approached for the solution I thought do some more search & research. I came across this blog of abdul qabiz; there in one thread I found some useful information and came across a mention of another website Flex Pasta". There I found the solution to my problem that I can use
ExternalInterface to get this domain information and many other information variables like port or URL parameters.
So here I found the solution. I created a small code snippet to test it and see how it’s working on a different domain; I created 2 text fields on stage in AS2 file:
ActionScript 2:
import flash.external.ExternalInterface;
try{
txtDomain.text = ExternalInterface.call("window.location.hostname.toString");
}catch (myError:Error) {
txtError.text = ("error: "+myError);
}
So it worked locally for me. But when I hosted this file on one website and pasted embed code in one blog, I got null as the value in the textfield. Then I tried to look into the Adobe help docs; there I found that if any error occurred it will return null. So I just tried to do some checkup on the Internet and then I found that allowScriptAccess must always be set as always; then only it will return the value.
So I am again stuck in the middle! I will be able to return the track of only those blogs, which will allow me to embed the code with allowscriptaccess as always but due to security threats many of the major blogs have already changed it; they have set it's value as never so you can't embed any third party swf file into these blogs with allowscriptaccess tag with value other then never. So does that mean you can't get domain name track backs from these blogs? I tried to do try catch as you see in the above code but nothing was returned in AS2 other then null.
So I read one comment in the Abdul Qabiz blog that he got a security error back in try catch and in that string he got where it was occurred along with the swf file path. I tried that in ActionScript3/CS3 file something like this:
import flash.external.ExternalInterface;
var loc:*;
try{
loc = ExternalInterface.call("window.location.href.toString");
}catch (e:SecurityError) {
test.text = ("error caught: "+e);
}
txtDomain.text = String(loc);
I mentioned the variable type of loc as "*" because I read a comment from senocular on Flashkit that the variable returned by ExternalInterface.call is of type "*". When I tried to assign that value to textfield it gave me an error: TypeError: Error #2007: Parameter text must be non-null. So there I have to typecast the variable as String to remove the error. Now when I published the file and tried that with 'allowscriptaccess' set to 'never' in embed code, I got a flash player error alert popup which said that the following swf can't access the following html file in which it is embedded.
Now as html page is hosted on the domain for which I was looking i.e. I can parse out the domain name from that error but an alert is not something a visitor likes to see. I put that call in try catch and got the error trace which has domain name in html page reference in catch block.
Similarly if you want to do it in Flex application you can do it something like:
import flash.external.ExternalInterface;
private var dom:*;
private function init():void{
try{
dom = ExternalInterface.call("window.location.hostname.toString");
}catch(e:SecurityError){
dom = "error: " + e.toString();
}
}
Init method can be called up on creation complete event of application.
Another problem which I came across this whole process was that during my tracing I noticed that although I can trace up external interface call in Firefox and Safari but Internet Explorer was not responding to the call. When I dug upon it a bit I found on one of the forums that specifying the flash file id in Object tag is a must to make sure your ExternalInterface call go through and return you a value. For e.g.<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' width='481' height='402' id='player'>
Tuesday, April 29, 2008
Best Practices for Development and Architecture for Flash Media Server
Uploaded on authorSTREAM by vivek
Saturday, June 23, 2007
Answer these Questions
1. If all the nations in the world are in debt (I am not joking. even US has got debts), where did all the money go? (Weird)
2. When dog food is new and improved tasting, who tests it? (To be given a thought)
3. Who copyrighted the copyright symbol? (Who Knows?)
4. Can you cry under water? (Let me try)
5. Why do people say, "Youve been working like a dog" when dogs just sit around all day? (I think they meant something else)
6. Why are the numbers on a calculator and a phone reversed?
7. Do fish ever get thirsty? (Let me ask and tell)
8. Can you get cornered in a round room?
9. What does OK actually mean? (OK, I don't know)
10. Why do birds not fall out of trees when they sleep? (Tonight I will stay and watch)
11. If corn oil is made from corn, and vegetable oil is made from vegetables, then what is baby oil made from? (No comments)
12. What should one call a male ladybird? (No comments)
13. If a person suffered from amnesia and then was cured would they remember that they forgot? (Can somebody help?)
14. Why is it called a "building" when it is already built? (Strange isn't it)
15. If you were traveling at the speed of sound and you turned on your radio would you be able to hear it? (Got to think scientifically)
16. If you're traveling at the speed of light and you turn your headlights on, what happens? (I don't have a change to try)
17. Why is it called a TV set when there's only one? (Nice one)
18. If a person owns a piece of land do they own it all the way down to the core of the earth?
2. When dog food is new and improved tasting, who tests it? (To be given a thought)
3. Who copyrighted the copyright symbol? (Who Knows?)
4. Can you cry under water? (Let me try)
5. Why do people say, "Youve been working like a dog" when dogs just sit around all day? (I think they meant something else)
6. Why are the numbers on a calculator and a phone reversed?
7. Do fish ever get thirsty? (Let me ask and tell)
8. Can you get cornered in a round room?
9. What does OK actually mean? (OK, I don't know)
10. Why do birds not fall out of trees when they sleep? (Tonight I will stay and watch)
11. If corn oil is made from corn, and vegetable oil is made from vegetables, then what is baby oil made from? (No comments)
12. What should one call a male ladybird? (No comments)
13. If a person suffered from amnesia and then was cured would they remember that they forgot? (Can somebody help?)
14. Why is it called a "building" when it is already built? (Strange isn't it)
15. If you were traveling at the speed of sound and you turned on your radio would you be able to hear it? (Got to think scientifically)
16. If you're traveling at the speed of light and you turn your headlights on, what happens? (I don't have a change to try)
17. Why is it called a TV set when there's only one? (Nice one)
18. If a person owns a piece of land do they own it all the way down to the core of the earth?
Monday, May 7, 2007
Tuesday, May 1, 2007
Tower Around the World
Subscribe to:
Posts (Atom)


