Entries Tagged as 'Flash'

Intro to Flashvars | Passing variables to flash actionscript from the html embed | Tutorial | passing dynamic variable from php file

Overview

The property “FlashVars” can be used to import root level variables to the flash movie or swf. The flashvars propery is used in codes for embedding flash in the html page. The string of variables passed in as flashvars, will be imported into the top level of the movie when it is first instantiated. Variables are created before the first frame of the SWF is played. The format of the string is a set of name=value combinations separated by ampersand (&) symbols. Here’s some sample embed codes, including object and embed tags:

<object width=”540″ height=”240″ title=”sample”> <param name=”movie” value=”flashvarsTutorial.swf” /> <param name=”flashvars” value=”var1=here&var2=are&var3=my&var4=flashvars” /> <embed src=”flashvarsTutorial.swf” flashvars=”var1=here&var2=are&var3=my&var4=flashvars” type=”application/x-shockwave-flash” width=”540″ height=”240″ ></embed> </object> Actionscript using flashvars :- txt1.text=var1;


Javascript from flash script Accessing javascript from flash getUrl flash

Creating pop-up browser windows in flash

Flash can trigger a browser pop-up in many ways, this sample explains how to do this by JavaScript.We can use javascript in flash in very simple way.Just create a function in javascript and place that in header.In flash file you have only to use getUrl function for accessing that javascript function.

<!–adsencestart–>

Code to write in the flash file

Create a new flash file, create a simple button in it, click the button and type this code on the flash button:

on (release) {
getURL("javascript:openNewWindow('http://www.macromedia.com','thewin',
'height=400,width=400,toolbar=no,scrollbars=yes')");
} Code to write in the html page:-

Now open the html page that contains the swf button and place this code between <head>…</head> area of the html code:

<script language="JavaScript">
function openNewWindow(URLtoOpen, windowName, windowFeatures) {
newWindow=window.open(URLtoOpen, windowName, windowFeatures); }
</script>

Now you are done. When the flash button is clicked then the flash button will trigger the JavaScript from the html page.

Options

You can adjust the first code (the on on the flash button) in order to adjust pop-up window options as follows: url to open, window name, height, width, toolbars (yes/no) and scroll bars (yes/no).

or also you have another like choice:-Code to go in html page top

<script language=”javascript”>
function redirect_now()
{
window.location=”yahoo.com”;
}
</script>

Now code for flash button:-

on (release) {
getURL(“javascript:redirect_now()”);
}


Flash and PHP contact form actionscript Creating contact mail form in flash

About php and flash contact form

This is a contact form made in flash and php, it can be used on ‘contact us’ pages.
A flash file contains the form items and when the ‘send’ button is pressed it sends the values to mailer.php, this mailer.php sends the email to the receiver.

Few of the benefits of using a flash form instead of a html contact form are:
better user interface
less junk messages (automated scripts cannot send emails through a flash form unless it is decompiled)
Usage details

Upload mailer.php and form.swf on your server in same directory.
In mailer.php you will have to replace ‘email@yourserver.com’ with your email address. Make sure this is an email hosted on that server where you are testing (most server requires this).
Preview

This is a preview of how the contact form looks, you try sending an email to see how form reacts, email will not be sent. It shows a warning if some of the fields are not filled.

<?php
/* —————————
php and flash contact form.
by www.MacromediaHelp.com
—————————
Note: most servers require that one of the emails (sender or receiver)
to be an email hosted by same server, so make sure your email
(on last line of this file) is one hosted on same server.
————————— */

// read the variables form the string, (this is not needed with some servers).
$subject = $_REQUEST["subject"];
$message = $_REQUEST["message"];
$sender = $_REQUEST["sender"];

// include sender IP in the message.
$full_message = $_SERVER['REMOTE_ADDR'] . “\n\n” . $message;
$message= $full_message;

// remove the backslashes that normally appears when entering ” or ‘
$message = stripslashes($message);
$subject = stripslashes($subject);
$sender = stripslashes($sender);

// add a prefix in the subject line so that you know the email was sent by online form
$subject = “Contact form test”. $subject;

// send the email, make sure you replace email@yourserver.com with your email address
if(isset($message) and isset($subject) and isset($sender)){
mail(“email@yourserver.com”, $subject, $message, “From: $sender”);
}?>
Contents of the FLA flash file (ActionScript)
stop();
send_btn.onRelease = function() {
my_vars = new LoadVars();
my_vars.sender = email_box.text;
my_vars.subject = subject_box.text;
my_vars.message = message_box.text;
if (my_vars.sender != “” and my_vars.subject != “” and my_vars.message != “”) {
my_vars.sendAndLoad(“mailer.php”, my_vars, “POST”);
gotoAndStop(2);
} else {
error_clip.gotoAndPlay(2);
}
my_vars.onLoad = function() {
gotoAndStop(3);
};
};
email_box.onSetFocus = subject_box.onSetFocus=message_box.onSetFocus=function () {
if (error_clip._currentframe != 1) {
error_clip.gotoAndPlay(6);
}
};


How to open Named Anchor links in flash actionscript

Writing 70-536 and 70-642 is not a big issue for a 642-642 professional, especially since they all have done 350-018 as well as 70-647 and 640-816 earlier in their careers.

About anchor links

In html you can link to a speciffic area of a html page by adding anchors, for example this link will point you to the “solution” area of this page; you link to an area of a page (to an anchor) by adding # after file name followed by the anchor name, e.g: products.php#product4 or just #product4 if destination is on same page.

The ‘namedanchor’ (destination) is written like this in the html code.


The flash issue

When you want a flash button to open a Named Anchor inside the html page normally you would think that the link can be open by something like this:

getURL(‘products.php#product4′);

but the above will not work because of some flash limitations
Solution

Write a really short javascript in the html page and set the getURL from flash to trigger that JavaScript.

Write this function in … area of html code:

Modify getURL actions from flash to call the above JavaScript:
getURL(“javascript:openNewWindow(‘anchor_test.html#title2′,’_parent’)”;

This solution was tested and worked in both Internet Explorer and Mozilla Firefox type browsers.


Simple Flash and XML sample Learning flash and xml

About this article

This article will show you basic connection between flash and XML, it will show you what to add in the flash file in order to be able to read tags from an XML file and then use that data inside flash.

Few details about the XML file

The XML that we will use will look like this, you can create a file called sample.xml and paste this in it:

<?xml version="1.0" encoding= "UTF-8" ?>
<products>
<product product_name="Flash Book" price="25.00"></product>
<product product_name="Flash CD" price="10.00"></product>
<product product_name="Dreamweaver CD" price="50.00"></product>
</products>

In the above XML file the “products” are called XML tags and “product_name” and “price” are called attributes.
“Products” is the first child of the XML file and the lines inside are child 0,1,2 of the first child.

To get the value “Flash Book” you have to write this in ActionScript:
my_xml.firstChild.childNodes[0].attributes.product_name
To get the value “Flash CD” use this code in ActionScript:
my_xml.firstChild.childNodes[1].attributes.product_name

The flash file preview

Contents of the flash file

In our samples we created 6 text fields where the data (product names and product prices) is written but is not important how you use the data, in this article we want to explain how to read the XML data.

Now the contents in the flash file…. open Macromedia Flash, create a blank file, click on first key frame, open Actions panel and paste this code:

// define an XML object called "my_xml"
my_xml = new XML();
// load data from an external XML file into "my_xml" object
my_xml.load("sample.xml");
// what to do when data is loaded ... Call a function ("my_function" in this case)
my_xml.onLoad = my_function;
// ignore "white spaces", text nodes that only contain white space are discarded
my_xml.ignoreWhite = 1;
// function contents
function my_function() {
// take the data from the XML lines (line 0,1,2) and place that data inside text fields
text_field_1.text = my_xml.firstChild.childNodes[0].attributes.product_name;
text_field_2.text = my_xml.firstChild.childNodes[1].attributes.product_name;
text_field_3.text = my_xml.firstChild.childNodes[2].attributes.product_name;
//
text_field_a.text = my_xml.firstChild.childNodes[0].attributes.price;
text_field_b.text = my_xml.firstChild.childNodes[1].attributes.price;
text_field_c.text = my_xml.firstChild.childNodes[2].attributes.price;
}

As you may see, the above code loads data from an external XML file called “sample.xml” and places the data from the XML tags to text fields inside the flash file.

For example: to access the product name on first line (“Flash Book”) the ActionScript line inside the flash file will be like this:

my_xml.firstChild.childNodes[0].attributes.product_name

“my_xml” is the name given to the new XML object at beginning of ActionScript code; the next code are the levels, it reads from first level (“firstChild”) this is “products” tag, from “products” tags it loads first child (“childNodes[0]“) and the attribute name is “product_name”.
So the above line will return the value “Flash Book”.
As you can see counting starts from zero when counting XML lines.

Product_name, price and XML tags are defined by user, in an XML file you can name the tags and the attributes as you wish, the tags are not predefined like in HTML language.