I was trying out the FJIK and I couldnt figure out why my calls to an actionscript function were working locally but not in the browser. Figured out I needed to do a System.security.allowDomain() in the swf recieving the function call. I just wanted to post that because i didnt see it in the docs and I couldnt find it while googling.
FlashApe » archive for 'DOM/Javascript'
Flash Javascript Integration Kit and security
- April 13th, 2006
- 8:50 pm
Simple function for emptying a DIV
- May 24th, 2005
- 1:14 pm
I was running into a litle trouble trying to empty a DIV of its contents the other day. I was trying to loop over the div’s childNodes array, and doing a removeChild() from each item in the array. Howerver that won’t work…the childNodes array holds ALL nodes, text, elements(which are HTML tags) and the elements’ attributes nodes. So, if you are looping through the childNodes array, and you delete an element, you are going to delete the attributes that are holding other positions in the childNodes array, and javascript will throw an error.
So, here’s a litle function I wrote for clearing out a div. It just checks each node’s nodeType first to see if if is an element node (nodeType = 1) or text node (nodeType = 3) before removing it.
function emptyDiv (divToClear){
var i;
while (i=divToClear.childNodes[0]){
if (i.nodeType == 1 || i.nodeType == 3){
divToClear.removeChild(i);
}
}
}
it feels like there’s probably a better way to pull that loop off…if you do know a better way please leave it in the comments.
LoadVars for Javascript updated
- May 9th, 2005
- 1:14 pm
I just updated my LoadVars object for javascript…you can now use either GET or POST with your send or sendAndLoad requsts. It defaults to POST. Also fixed a little bug in the onData method that would output two equals signs if one was sent back as part of the response.
You can get the source files here
View a demo here.
See my previous post for some more notes.
actionscript
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)
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
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)
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)
Determining browser through Object Detection
- October 12th, 2004
- 1:14 pm
Found an interesting article on the Apple Developer’s Connection that talks about the benefits of using Object detection to determine a user’s browser. The article talks about the many pitfalls of using the more common “browser-sniffing” method of searching the Navigtor object to determine version info.
From the article:
Browser sniffing Ñ the task of inspecting navigator object properties for version information Ñ has become largely unmanageable given the browser version permutations available today. This article presents details on an alternative solution Ñ object detection Ñ that frees JavaScript developers from most of this versioning mess.