Best way to implement a flash website banner - c#

I am a c# asp.net developer and need to implement a number of flash website banners. Previously for static image banners I have implemented on_click code behind or javascript to log the banner has been clicked back to a database and process the re-direction.
I don't have much knowledge of flash other than I know that a flash program can handle on-click events of the program.
Therefore, can somebody suggest the best solution for capturing and processing on-click events of a flash object on a webpage.
Many thanks,
Adam

You can talk to Flash objects with JavaScript via Mootools' Swiff component:
http://mootools.net/blog/2008/02/12/whats-new-in-12-swiff/
http://mootools.net/docs/core/Utilities/Swiff
However, for simple things like clickable banners, all you may need is swfobject:
http://code.google.com/p/swfobject/
A decent but simple XML driven Flash banner rotator can be had for free here:
http://www.weberdesignlabs.com/blog/2008/06/open-source-xml-free-flash-banner/
Hope that helps!

You can communicate in multiple ways with Flash and your Server Side Code.
1.) Use JavaScript to communicate to/from your SWF file and the page it is embedded in.
http://kb2.adobe.com/cps/156/tn_15683.html
This can be combined with AJAX to send data to the server.
2.) Directly send variables to a Server Side File (using GET or POST) within Flash
http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001790.html
var submitListener:Object = new Object();
submitListener.click = function(evt:Object) {
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
result_ta.text = result_lv.welcomeMessage;
} else {
result_ta.text = "Error connecting to server.";
}
};
var send_lv:LoadVars = new LoadVars();
send_lv.name = name_ti.text;
send_lv.sendAndLoad("http://www.flash-mx.com/mm/greeting.cfm", result_lv, "POST");
};
submit_button.addEventListener("click", submitListener);
You can have a Server Side Page (ASP.NET, PHP, etc...) to increment the Database hit count.

Related

How can I make a windows app in C# that for example automatically follows someone on Twitter when I open it up?

If I were to follow USA Today on Twitter with a JavaScript code I could go to their page and paste this simple code in the console:
follow();
function follow(){
var button = document.getElementsByClassName("EdgeButton EdgeButton--secondary EdgeButton--medium button-text follow-text")[0];
button.click();
}
How can I trigger this code on a specific URL in C# (only after the page loaded)?
So what I'm trying to ask is how can I trigger a button in C# remotely, without actually visiting the page?
So it could be a simple console application too where I simply
string jsCode = "follow();
function follow(){
var button = document.getElementsByClassName("EdgeButton EdgeButton--secondary EdgeButton--medium button-text follow-text")[0];
button.click();
}";
string url = "https://twitter.com/";
List<string> pagesToFollow = new List<string>();
pagesToFollow.Add("USATODAY");
pagesToFollow.Add("RT_America");
pagesToFollow.Add("Reuters");
foreach (var s in pagesToFollow) whateverMethodGoesHere(url + s, jsCode);
This is pretty much what the app would look like but I have no idea how to execute a JavaScript code remotely and I yet to find a solution to the problem that the code should wait until the page is loaded.
Considering it a general question as you request, a general answer would be something like this:
Use a proxy, like Fiddler, and study the HTTP requests done while performing the task you want to emulate. Then, replay the requests from your program.
Embed a headless browser like Chromium and control it from your code.
Use Selenium. There is a binding package in NuGet.
... and many more, I suppose. This question is really open to speculation.

Passing values from c# to actionscript 3 and crossdomain questions

I have a c# console application that I want to use for a game server
the client is being written is as3.
I am going to embed the swf into a c# form later.
I have a couple questions, I'm really hoping someone can help me figure this out.
Currently I have it set up to send a request to log in to the server, at which point the server checks information you put in the username and password fields
and verifies the information.
If you are authenticated you get connected.
My issue is I can't figure out how to send specific information back to flash, such as a string or int.
I want to do this for things like displaying user stats for example.
I looked at many tutorials but most are about using a flash application that is embedded in a c# server application, and does not operate the same way I need it to.
I just want to send a string or int from my c# server to my flash application that I have retrieved from mysql.
so if anyone can just show me how to send a string or int to flash as a raw value please let me know :)
If you can please post a snippet of code... I am still very new as3 c# communication.
also if you need the source please contact me on skype
Skype = Serifaz2
I don't want to just publicly post it ... sorry :(
Nevermind I figured it out. It was actually pretty simple.
C#
Socket socket = TcpClient.Client;
string UserTest = "" + Username;
try
{ // sends the text with timeout 10s
UserInfo.Send(socket, Encoding.UTF8.GetBytes(UserTest), 0, UserTest.Length, 1000000);
}
catch (Exception ex) { /* ... */ }
AS3
while(socket.bytesAvailable)
{
var str:String = this.socket.readUTFBytes(this.socket.bytesAvailable);
trace(str);
myTrace("you have something");
}

Facebook "fan gate" with C#/asp.net

The problem is that 1) Facebook seems so fluid with how it allows developers to interact with it (FBML, iFrame, different versions of SDKs) and 2) Everything I find is either PHP or Javascript and I have NO experience with those. What I am trying to do seems sooo simple, and I can't believe there isn't an easy way to do this.
What I have:
I used Visual Studio 2010 to create a simple web application (asp.net/C#) that asks the user for some info (first name, last name, email, etc.). I have a button on there called "Submit" that, when clicked, saves the entered data into a database. I have this hosted on GoDaddy (I know, I know...heh) and it works just fine. No problem here.
I created a "Facebook App" that uses the iFrame thingy so that basically I have a new tab on Facebook that displays my web app mentioned above. This works fine too. The tab is there, the web app is there, and users can enter the data and it is saved to the database. No problem here.
What I WANT:
I want the web app (the thing displayed by the facebook app) to only show the data entry part if the user currently "likes" the facebook entity. I DO NOT want to have to ask permission. I just want to know if they are a fan of the company's facebook "page" that has this app. So I need two things here, shown in my pseudo code below:
Part 1 (check if user is already a fan):
If (user is fan)
{
Show data entry area (unhide it)
}
else
{
Show "Click the like button to see more options"
}
Part 2 (listen for "like" event)
WhenLikeButtonPressed()
{
Show data entry area (unhide it)
}
I've seen stuff about "visible to connection", C# sdk, edge.create, etc. but I just can't make heads or tails of it. I don't mind putting in Javascript or PHP if someone could please give me exact, "Fan Gate for Dummies" steps. Please, I'm going crazy over here :-(
The key is is the signed_request that Facebook posts to your app when the user accesses the page. It contains the data on whether or not the user likes the page. You shouldn't need to worry about catching edge events on an actual tab FB page as it get's reloaded when the user likes/unlikes the page.
You'll need to decode the signed request with your app secret to get the like info. There are examples provided for PHP but I'm sure with a little google help you can find decode info for the signed_request for asp.net/c#.
Here's the php decode for reference:
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
and the link https://developers.facebook.com/docs/authentication/signed_request/ the like info will be contained in the page variable

Receive data from PostBack in JavaScript

I'm using jQuery to make postback then in my .ascx file I have code like this:
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
if (args.get_error() == undefined) {
var dataItems = args.get_dataItems();
alert(dataItems['ctl00_cphContent_articleList_tbUpdate']);
}
}
Where on the Internet can I find specification of args object? What methods has it got?
Second, why do I have to pass in my server side data into control using ScriptManager?
Code on the server side is:
ScriptManager.GetCurrent(this.Page).RegisterDataItem(tbUpdate, DateTime.Now.ToString());
and tbUpdate is the control on the site.
Is there any more elegant way to get access to data sent back to the client side. Do I have to send this data to any control? What does it really mean that data is sent to control?
How can I consume this data from that control? I had to use Firebug to find the id of the control and get access to it.
It sounds like you're trying to do an AJAX call to the server, and use the resulting data client side to either inject into an existing control, or create new controls for the data from the server.
I can only suggest you read these articles that explain how this works in far more detail than I can go into in an answer here:
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
and
http://encosia.com/using-jquery-to-consume-aspnet-json-web-services/
These are the clearest and most concise documents I have found on the subject.

Automate login to a site and click a button

To need to login to a site, go to a particular page (eg. local router page) and click a button to do an operation(eg Connect). Since I do it almost everyday, I thought of automating it through small C# application. I don't have any idea how to do it.Any pointers?
Why code C# for one click? Try AutoIt.
Here is a starter tutorial. This will help you to quickly automate clicking on the default buttons of an application. Some more tricks from AutoIt and you will be able to do almost anything you can tell someone over the phone to do on the GUI.
AutoIt is a useful tool to keep handy if you are working with GUI testing or were dreaming of scripting a lot of routine GUI activity.
Capture the content of the HTTP-request using a tool like Fiddler. With this information you can build an application that executes these HTTP-requests.
Trace the HTTP requests your sending using
a browser plugin (Firebug, httpwatch, tamperdata, etc.)
a web debugging proxy (fiddler, charles, etc.)
a packet sniffer (wireshark, etc.)
And then use the classes in the System.Net namespace (e.g. WebClient) to execute the same requests.
You can also use the Selenium IDE, which is a FireFox plugin that allows you to record macro like scripts for playback in the browser. It is designed for automated testing of web pages, but you can export the script in C#, which can in turn be run from a console app.
If you plan to run it as a C# app, you will also need to look at Selenium RC.
Happy scripting :)
I have created app in C# which uses the WebBrowser control provided by Microsoft
and used it to ope a website and tried to manipulate it's html and tried to put values in
some text boxes and tried to hit the button it works for me ,hope it's helps for you as well
Sample code is as follow
internal void LoginToSite()
{
WebBrowser.Navigate("some site login Page");
_Processing = true;
var username = ConfigurationManager.AppSettings["username"];
var password = ConfigurationManager.AppSettings["password"];
while (_Processing)
{
Application.DoEvents();
if (WebBrowser.ReadyState == WebBrowserReadyState.Complete || WebBrowser.ReadyState == WebBrowserReadyState.Interactive)
{
var htmlDocument = this.WebBrowser.Document;
if (htmlDocument != null)
{
foreach (HtmlElement tag in htmlDocument.GetElementsByTagName("input"))
{
switch (tag.Name)
{
case "username":
tag.InnerText = username;
break;
case "password":
tag.InnerText = password;
break;
case "cmdlogin":
tag.RaiseEvent("onclick");
tag.InvokeMember("Click");
break;
}
}
}
_Processing = false;
}
}
}

Categories

Resources