Archive

Archive for March, 2009

Contact Form Changes from v1.1 to v1.2

March 14th, 2009

globals.php

This is a guide for Contact Form with Mail Attachments component and specifies what has changed from v1.1 to v1.2.
For a step-by-step installing guide for this component check the Step-by-step installing guide but keep in mind the changes in this post.
Contact Form with Mail Attachments is a Flash, actionscript 3, mail contact form component that suppports multiple mail attachments. The server side script is in php.
 

added $UPLOAD_CONTAINING_FOLDER : this is where the upload directory can be set.

Note that the directory set here must exist! It default to “./files/” but you still need to create it. This directory is relative to where the php script files are located.

upload_file.php

now requires “globals.php”: it looks after $UPLOAD_CONTAINING_FOLDER as it will upload files into this folder(actually it will create new temporary directories)

Safety check added here

sendmail.php

and same safety checks added here too.

 

Fixed issues with php scripts

php would diskard files bigger than the maximum file upload (from php.ini) and upload script would fail: fixed now

sendmail.php would fail to delete the created files and directory upon completion: fixed

Contact form

The swf file: fixed bugs and issues and made more robust.

if files were selected for upload, then all the files delete from the list and the form submitted, an error was thrown by flash: now it’s taken into account

some other minor bugs fixed

if something is not working right, please check out the flash log file (flash player debugger version is required) as important information can be output about what the cause of the problem might be

This version should be installed ASAP!

http://www.flashcomponents.net/component/contact_form_mail_with_attachments.html?ref=pinosh

Components, Contact Form With Attachments v1.1 , , , , ,

Step-by-step installing

March 8th, 2009

This is a tutorial that shows how to install the Contact Form with Mail Attachments component.
Contact Form with Mail Attachments is a Flash, actionscript 3, mail contact form component that suppports multiple mail attachments. The server side script is in php.

Customize globals.php

 

Set here the server details that match your identity.

  • $TO : Set this to be the email address to which the message will be sent  (likely your email)
  • $SUBJECT : Set here the subject of the mail (sent to the $TO address);  <NAME> will be replaced by code with the name of the sender (filled in the ‘Your Name’ field of the form)
  • $CONFIRMATION_SUBJECT : The subject of the confirmation mail (the confirmation mail will be sent to the mail address of the sender: filled in the ‘Your Email’ field of the form)
  • $CONFIRMATION_MESSAGE : Set in this variable the body of the confirmation mail (the confirmation mail will be sent to the mail address of the sender: filled in the ‘Your Email’ field of the form, it confirms that his mail was successfully sent; it also contains a copy of his original message)
  • $CONFIRMATION_NAME : Set here your name; will appear in the header of the mail in front of $CONFIRMATION_MAIL (John Doe [mail@example.com])
  • $CONFIRMATION_MAIL : Set this to be your mail (will apprea near your name: John Doe [mail@example.com])

 

Install the scripts

 

  • Inside the directory where you want to install your app, create a subdirectory ’scripts’. Make the directory permissions 775: rwx-rwx-r-x (this is because flash player will directly access the scripts and php will need r-w permissions here: creates directories and stores uploaded files, then deletes them after the email is sent)
  • Copy all the php scripts inside this newly created directory. Make each file’s permissions 644: rw–r—r–

Install the flash files

 

  • Inside the directory where you want to install the contact form, outside the ’scripts’ directory (you don’t need to install where the scripts directory is, you can install anywhere as the paths to the scripts can be configured in contact.xml file): copy all the necessary files – contact.swf, AC_RunActiveContent.js, contact.html and data directory
  • Make sure that the files have 644 permissions, data directory should have 755, and contact.xml from inside data directory should also be 644

Customize data/contact.xml file

 

  • Open data/contact.xml file in a text editor (notepad will do great, don’t use a word processor like MS Word)
  • Inside this file, the <php> tag must be edited to reflect the real script paths: <mailscript> tag, set it’s path attribute to be the path to the ’sendmail.php’ script; <upload_script> tag, set it’s path attribute to be the path to the ‘upload_file.php’ script – these paths can be relative or absolute;

 For example:

<php>
<mailscript path="scripts/sendmail.php" />
<upload_script path="scripts/upload_file.php" />
</php>

This assumes that the ’scripts’ directory is in the same directory as ‘contact.swf’ file

  • Everything else in the xml file is optional, meaning it can be left as it is
  • <title> : The Title that appears at the top of the contact form
  • <yourname>, <yourmail>, <message> : <caption> – ‘optional’ attribute specifies whether the current field is optional or required when validating the form: valid values “true” – meaning optional, “false” – meaning required; The text inside the <caption> tag is  the text that will appear next to the corresponding text field;

<text> – ‘default’ attribute sets the default text that appears inside the corresponding input text field; when this textfield receives focus, this text will be cleared; ‘clearOnClose’ attribute specifies whether the text inputted will be cleared when the form is closed or not: valid values “true” – meaning the text will be cleared, “false” – the text will remain uncleared, so that when the form is reopened, the last text inputted in this filed it’s still there

  • <error>:  <messages> – sets the error messages when the form is not filled correctly
    • <yourname>, <yourmail> and <message>: ‘empty’ attribute – this error will be displayed when the input textfield is empty and the textfield has been declared as required (see previous point)
    • <yourmail>: ‘notValidated’ attribute – this error appears when the email entered in the <yourmail> tag is not a valid email address
  • <close>: if  ‘visible’ attribute on <button> tag is ‘true’, the close button is visible, if it’s ‘false’, it’s not visible
  • <submit>: <event> : ‘closeFormUponSubmit’ – valid values: ‘true’ – meaning the form will be closed if the form is successfully submitted, ‘false’ the form will not be closed
  • <files> : <upload_file> : ‘max_file_size’ set this the maximum allowed file size in KiloBytes; if the file is bigger than this value, the file will not be added to upload list
    • <file_filter>:  ‘type’ attribute – Set the type of files allowed by this filter; accepts wildcards (*): to allow mp3 files ‘*.mp3′; to allow more types by one filter: ‘*.mp3;*.wav’; ‘description’ attribute – Sets the description associated with this filter; These filters work based on file extensions!

 

 

To set file attributes in terminal:

chmod UGO file

Where UGO is the file perrmission: U – user permission (owner)

G – group permission

O – others permission (public)

1 – execute

2 – write

4 – read

Example: 644 – U=2+4=write+read

G=4=read

O=4=read

Components, Contact Form With Attachments v1.1 , , , , , , ,

Flash CS4 TextField: embedded fonts

March 4th, 2009

Embedding a font in AS3 in Flash CS4 seems more challenging than at a first glance.

Flash had problems with fonts and texts for a very long time, but the new editor adds up problems rather then removing them.

Soo, here is what should always work when creating a textfield dynamically:

Firstly, embed the font you want to apply for your textfield inside the editor: in the library, right-click, select New Font…

Set a name for the font (you can leave it  as it is), choose the font you want from the Drop down, select a style (if any is available), if not you can check the appropriate Faux box..

The size property has effect only if you select the Bitmap option: this option specifies that the font will be embed as bitmap rather then vector

Since we’ll use this font in code, we must set a Linkage for it: check Export for actionscript, leave checked Export in frame 1, and in the Class field set a name you want: let’s say MyFont, leave the base class to be Font and click ok

A warning popup should appear saying that there’s no class MyFont found in the classpath and Flash will create one for us: that’s ok, that’s exactly what we want

Soo, the class MyFont will be created by Flash and it will have the base class Font.

ok.

Now we can create the textfield in code

You can write the code on the first frame or on a separate file inside a class.

I’ll just create a new class that extends MovieClip and set this class as the document class for my swf

package textfield{
import flash.display.MovieClip;
import flash.utils.getDefinitionByName;
import flash.text.TextFieldAutoSize;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.Font;

public class Main extends MovieClip {
public function Main() {
super();
this.createTextField();
}

private function createTextField() : void {
// create the textField object
var text : TextField = new TextField();
// optionally set a name for the textfield, so we can refer to it, if we need to, later
text.name = "text";
// set the autosize option to "left"; using constants is more error proof
text.autoSize = TextFieldAutoSize.LEFT;
// set the the multiline property to be true; so we can have multiple lines in it
text.multiline = true;
// true so that line wrap at words end (at white characters)
text.wordWrap = true;
// the key to whether the font will be embedded (true) or not (false) in the swf
text.embedFonts = true;
// set size and positions of the text field
text.width = 200;
text.height = 150;
text.x = text.y = 100;

// we get a reference to the definition of the MyFont class (the class of our font created in the library)
// we could have just used 'MyFont' directly, but some editors, like FDT, complain about it, saying that the specified definition does not exist, and if we have errors, the editor will not give us code completion... corectly; the point is we can do without it
var MyFontClass : Class = getDefinitionByName("MyFont") as Class;
// create an instance of our font class
var myFont : Font = new MyFontClass() as Font;

// in order to specify what font we'll use for our textfield, we need a textformat object
var textFormat : TextFormat = new TextFormat();
// set it's font property (String) to the name of our font
// you might notice that we could have passed in the name of the font directly, hard coded; and it would have worked; but it's safer this way; fonts may have different names on different OSs, so when compiling the fla on a different OS, the font might not be found, thus the text will not be displayed; although you might argue that the font is there; also it's easier to change the font; only change it in library and recompile
textFormat.font = myFont.fontName;
// set font size
textFormat.size = 16;
// set font color
textFormat.color = 0xff0000;

// apply the text format to the text; this only works if you're not using the stylesheet property of the textfield
// also, using defaultTextFormat property instead using setTextFormat method seems to work better; i couldn't find a reason for that, all i can think of, is that when setting the defaultTextFormat property, it takes only the values that are NOT NULL from the text format, and when using setTextFormat method, it sets all the values even if they are NULL; anyway, not even the old way, a combination of getTextFormat, setting the values needed, and setTextFormat, doesn't work anymore
text.defaultTextFormat = textFormat;

// set some text to see our text field; htmlText also works
text.text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";

// Add the text field in the display list of our document
this.addChild(text);
}
}
}

Where your fla is situaded on the file system (in the classpath) create a folder named ‘textfield’, inside this folder create a new file ‘Main.as’ and paste in the code above;
In your fla, set the Class property of the document to “textfield.Main”.
Compile and run the app, you should see the text in red.

If the text doesn’t appear, it means that the font is not embedded properly

Notice that i didn’t set the antiAliasType Property of the text field to be “advanced”, that’s because i noticed on some fonts, setting this property breaks the embedding mecanism, the text won’t show, the font will not be embedded.
however on most of the fonts it works, so you should try and see the result first.
You should keep in mind however, if the text doesn’t show, try not setting the property and see if it works without it.

You can check if your font is embedded: use the static method enumerateFonts of the Font class, which returns an Array of fonts: all the fonts installed on the system or only the fonts embedded in the swf, depending on the value of the enumerateDeviceFonts parameter
Here is the declaration of the method

static public function
enumerateFonts(enumerateDeviceFonts:Boolean = false):Array

if

enumerateDeviceFonts

is

true

, then it will return the list of all the fonts installed on the local machine
if it’s false will return an Array of all embedded fonts in the current swf

Hope it helps anyone

Actionscript 3.0 , , , , , ,