Skip to Content »

FlashApe » archive for April, 2005

 DOM-scripting

  • April 22nd, 2005
  • 1:14 pm

been starting to get into some javascripting lately (seems to make more sense to call it DOM-scripting, since you are pretty much always working with the Document Object Model, or DOM for short). It’s pretty cool the way you can dynamiclly add and remove content easily from the html page. And since javascript and Actionscript are so closely related, anyone comfortable with AS should easily be able to pick it up quickly. While looking around to find some info about it, I found a great little resource site: QuirksMode has some awesome info on javascript, the DOM, CSS and more. It’s mostly geared toward the the novice and those seeking more information on the basics and background of js, the dom, and css.
I know there’s a lot more like this out there, if anyone cares to share just drop a comment.
Posted by flashape at 11:10 AM | Comments (7)

 LoadVars for Javascript

  • April 22nd, 2005
  • 1:14 pm

I put together this LoadVars class for javascript for users who would rather deal with the flash LoadVars object than the XMLHttpRequest object (this LoadVars class is pretty much just a wrapper for that object). It’s quick and dirty but it works.
A few notes about the class:
¥ all requests use GET. the send and sendAndLoad methods will automatically convert the properties of the LV object to a query string and append it to the URL.
¥ You dont need to escape the return value coming back to the LV object. You can send a plain string if you like. However, you can set the LoadVars.parseVarString to true, and you can pass in a string like “myVar=This is the ver&myvar2=This is the secondvar.” You don’t need to encode the string, but if you do it will decode it.
¥ the return value is always accepted by the same LV object. In flash, you can specify a target object..that is not used here.
¥ only string or number datatypes may be used.
¥ getBytesLoaded/getBytesTotal aren’t implemented.
¥ there is a LoadVars.onLoadError method you can use to handle situations such as document not found.
You can test it out here.
You can grab the source files here.
Posted by flashape at 05:05 PM | Comments (1)

 Create New Element function

  • April 22nd, 2005
  • 1:14 pm

creating new elements and adding their attrubtes can be a little bit of a pain using the DOM…here’s a function that creates a new element, adds it’s attributes, and appends the new element to the given node:
function addNewElem (parentNode, newNodeName, attObj){
var node = document.createElement(newNodeName);
for(var p in attObj){
node.setAttribute( p “className” ? “class” : p, attObj[p]);
}
for(var i = 3; i

 createElement and events, and iframe borders

  • April 22nd, 2005
  • 1:14 pm

A couple more things i learned today about using the DOM: First, when you are creating elements using createElement, you can usually set your attributes by using myElement.setAttribute(attributeName, “attributeValue”). Well, I had a bitch of a time today trying to figure out why nothing was happening in IE with the onclick attribute for an ‘A’ element I was creating. In all the mozillas everything worked fine…the onclick function i was assigning was firing correctly.
It turns out, IE expects you a function, not a string value for the onclick reference. Mozilla browsers will parse the string for the function so you dont get an error. There’s a couple of different ways to reconcile this, but the easiest and most cross-browser compatible I found was to just directly assign the onclick handler a function literal:
myNewElement.onclick = function(){
//dostuff
}
Even more of a pain in the ass was when i was dynamically generating a ‘IFRAME’ using createElement. again, IE was giving me problems…this time i could NOT get the border around the new iframe to go away for anything…i was setting both the frameborder and border properties to “0″ (and even tried “no”), and it would work in mozilla, but not IE. I tried some CSS stuff, that didnt work either. Finally i tried using frameBorder=0 instead….and it worked. Damn platform-dependent case sensitivity.
javascripting still SUCKS, even with the DOM and its methods.
Posted by flashape at 05:02 PM | Comments (4)

 Cake PHP framework

  • April 20th, 2005
  • 1:53 am

Just saw this post over at Digital Media Minute about something called Cake, a PHP web application framework. I have to say after checking it out I’m really excited about it…I hope this sticks around and matures. I wonder how/if this would relate to using AMFPHP?
–update: After reading this post again, i realized how much of a TOTAL FREAKING GEEK i am for getting “really excited” about a php application framework…i love it though!!
Posted by flashape at 01:53 PM | Comments (2)
April 05, 2005
copy directory in php
While trying to figure out how to copy an entire directory to a new location (on the same web server) in php, I came across this function. I took that as a base and modified it to handle premissons better:
function copyr($source, $dest){
// Simple copy for a file
if (is_file($source)) {
$c = copy($source, $dest);
chmod($dest, 0777);
return $c;
}

// Make destination directory
if (!is_dir($dest)) {
$oldumask = umask(0);
mkdir($dest, 0777);
umask($oldumask);
}

// Loop through the folder
$dir = dir($source);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry ‘.’ || $entry ‘..’) {
continue;
}

// Deep copy directories
if ($dest !== “$source/$entry”) {
copyr(”$source/$entry”, “$dest/$entry”);
}
}

// Clean up
$dir->close();
return true;
}

 PHP XPath

  • April 4th, 2005
  • 1:53 am

Many flash developers are now using XPath in AS2, which is cool. I was working on a project the other day that was going to require some server-side manipulating of an XML document…so I did a searcha nd lo and behold, XPath in PHP does exist! (and already on version 3.5!)