June 16th, 2007
This is just an example of what can be done with loading from an xml file.
The xml code needs to go in the same directory and needs to have the same name as the swf, ie. loadXML.xml loadXML.swf
<?xml version="1.0" encoding="iso-8859-1"?>
<xml>
<imagesDepth>1</imagesDepth>
<textsDepth>0</textsDepth>
<textField x="50" y="0" width="100" height="50">This is being loaded from an xml file</textField>
<image x="50" y="100" width="50" height="50">http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif</image>
<textField x="6" y="8" width="100" height="50">I can position and resize this text to any size.</textField>
</xml>
And this code needs to go on the first frame in the root of the movie
function findXML(string) {
var num1:Number = string.lastIndexOf("/");
var num2:Number = string.lastIndexOf(".swf")+4;
var string2:String = string.substr(num1+1, num2-5-num1);
var string3:String = string.slice(num1, num2);
var array:Array = string.split(string3);
array[1] = string2;
return (array);
}
function loadXML() {
var array:Array = findXML(_root._url);
var xml:XML = new XML();
xml.onLoad = function(success) {
if (success == true) {
trace(”Loading of “+array[0]+”/”+array[1]+”.xml”+” succeeded”);
parseXML(this);
} else {
trace(”Loading of “+array[0]+”/”+array[1]+”.xml”+” failed”);
}
};
xml.ignoreWhite = true;
xml.load(array[0]+”/”+array[1]+”.xml”);
}
function parseXML(xml) {
var xmlChild:XML = xml.firstChild;
var xmlChildChild:XMLNode = xml.firstChild.firstChild;
var xmlChildChildChild:XMLNode = xml.firstChild.firstChild.firstChild;
imageA = new Array();
imageX = new Array();
imageY = new Array();
imageW = new Array();
imageH = new Array();
textA = new Array();
textX = new Array();
textY = new Array();
textW = new Array();
textH = new Array();
for (j=0; j<1000; j++) {
//trace(”RSS”+newline+xmlChildChildChild.nodeName.toUpperCase() )
if (xmlChildChild.nodeName == undefined) {
break;
}
trace(xmlChildChild.nodeName.toUpperCase());
if (xmlChildChild.nodeName.toUpperCase() == “IMAGESDEPTH”) {
imagesDepth = Number(String(xmlChildChild.firstChild));
}
if (xmlChildChild.nodeName.toUpperCase() == “TEXTSDEPTH”) {
textsDepth = Number(String(xmlChildChild.firstChild));
}
if (xmlChildChild.nodeName.toUpperCase() == “IMAGE”) {
imageA.push(String(xmlChildChild.firstChild));
imageX.push(xmlChildChild.attributes.x);
imageY.push(xmlChildChild.attributes.y);
imageW.push(xmlChildChild.attributes.width);
imageH.push(xmlChildChild.attributes.height);
}
if (xmlChildChild.nodeName.toUpperCase() == “TEXTFIELD”) {
textA.push(xmlChildChild.firstChild);
textX.push(xmlChildChild.attributes.x);
textY.push(xmlChildChild.attributes.y);
textW.push(xmlChildChild.attributes.width);
textH.push(xmlChildChild.attributes.height);
}
xmlChildChild = xmlChildChild.nextSibling;
}
trace(imageA);
initXML();
}
function initXML() {
texts();
images();
}
function images() {
loaded = 0;
_root.createEmptyMovieClip(”Images”,imagesDepth);
var imageLoader:MovieClipLoader = new MovieClipLoader();
var loadListener:Object = new Object();
imageLoader.addListener(loadListener);
loadListener.onLoadInit = function(mc) {
loaded++;
trace (mc.getDepth()-1)
mc._x = imageX[mc.getDepth()-1];
mc._y = imagetY[mc.getDepth()-1];
mc._width = imageW[mc.getDepth()-1];
mc._height = imageH[mc.getDepth()-1];
if (loaded == imageA.length) {
trace(”done”);
}
};
for (i=0; i<1000; i++) {
imageLoader.loadClip(imageA[i],Images);
}
}
function texts() {
_root.createEmptyMovieClip(”Text”,textsDepth);
for (i=0; i<textA.length; i++) {
var txt:TextField = _root.Text.createTextField(String(”text”+i), i, textX[i], textY[i], textW[i], textH[i]);
txt.text = textA[i];
trace (”text”+i)
trace(txt.text)
}
}
loadXML();
Click here to download sample Files
Posted in Blogs | 2 Comments »
May 15th, 2007
The Flash FileReference Class is a tool for uploading files by:
- Popping up a browse box, prompting the user to define the file they would like to upload
- Uploading the required file, using either php, coldfusion, or asp.
- Keeping Flash up to date on the progress of uploading the file.
- And returning to Flash either an error or else it notifies Flash that it uploading has been completed successfully.
The properties of the FileReference :Class are as follows:
- addListener(listener:Object) :Function
- browse(typelist:Array) :Function
- cancel:Function
- creationDate:Date[read-only]
- creator:String[read-only]
- download
- modificationDate:Date[read-only]
- name:String[read-only]
- onCancel:Function -runs when user cancels
- onComplete:Function -runs when uploading completes
- onHTTPError:Function -runs when a HTTPError is encountered
- onIOError:Function -runs when an IOError is encountered
- onOpen:Function -runs when file is Opened
- onProgress:Function -runs when upload progress is made
- onSecurityError:Function -runs when a security error is encountered
- onSelect:Function -runs when user selects which file to upload
- removeListener:Function
- size:Number[read-only]
- type:String[read-only]
- upload:Function
Judging by the number of people having problems with the FileReference class, a list of causes of errors would be helpful. If an error you are currently having is not listed, then please feel free to comment on it.
- 406 error
- This might be able to be fixed by going to the root directory on your site, and adding the following lines to .htaccess (if it is not there, then create it)
- or, on the other hand, if your page is under a secure connection,
Flash cannot upload under a secure connection, so if you are trying for example to upload to https://mysite.com/upload.php, it won’t work, because flash cannot upload under a secure connection, however, you can upload to http://mysite.com/upload.php
- or a combination of both
- If you would like to have an error listed, please comment on your error, and an administrator may add it to the blog
Also included in this blog is a list of other articles on the FileReference Class and it’s errors
The code for php is:
$fileName = basename($_FILES[”Filedata”][”name”]);
$uploadFile = “images/uploaded/” . $_GET[”date”] . “-” . $fileName;
if (move_uploaded_file($_FILES[”Filedata”][”tmp_name”], $uploadFile)) {
chmod(dirname(__FILE__) . “/” . $uploadFile, 0777);
print 1;
}else{
print 0;
}
?>
The code for coldfusion:
is available here
The code for asp:
<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”1252″%>
<%
Set theForm = Server.CreateObject(”ABCUpload4.XForm”)
theForm.Overwrite = True ‘ overwrite existing files
.
For Each theFile in theForm.Files
If theFile.FileExists Then
‘ save in virtual directory
theFile.Save “temp\” & theFile.FileName
Response.Write(”1 ” & theFile.FileName)
Else
Response.Write(”0″)
End If
Next
Set theForm = nothing
%>
If you have any comments or questions please feel free to let us know… and
Thanks for reading
…Also, a tutorial on this is coming soon!
Posted in Blogs | 26 Comments »
May 7th, 2007
I have been a Flash developer for a number of years, but until recently, i have not come across the setInterval() function. I have used the onEnterFrame function before, and although it does work properly, you are limited to just repeating at the current frame rate. SetInterval on the other hand, allows for more flexibility by allowing you to specify in milliseconds exactly how much time you want between each repetition of a function.
_root.onEnterFrame = function(){
refresh();
}
As you have probably already worked out, this code will run the function refresh() again and again every time the frame should be changed, even if there is only one frame in _root. However, the setInterval() will allow the user to define, exactly how often they want the function to repeat. For Instance:
setInterval(doStuff, 2000,"doThis","doThat")
function doStuff(a,b){
trace (a)
trace (b)
}
The Previous code will trace "doThis", and "doThat" once every 2000 miliseconds, or 2 seconds. Also, the Parameters for the setInterval() function are (functionName,timeInMilliseconds,anyParameters).
This Concludes our rundown on the setInterval() function.
If you have any comments or questions please feel free to let us know… and
Thanks for reading
Posted in Blogs | 1 Comment »