Jun 12 2009

Adapting iframe height to its content with 2 lines of javascript

Category: javascriptDavide Zanotti @ 2:38 am

In a project, I have to use an iframe and I need that its height is automatically calculated based on its content. However is not possible to accomplish this by simply setting the attribute height to 100%, instead we must smartly use javascript to dynamically assign that value after a computation. The solution I’m going to show you is not 100% my work but instead an optimization and a better implementation of clever intuitions I found on the web.
The “trick” works in this way:

1. The iframe should has an ID assigned:

1
<iframe id="slideshow_frame" src="frame.html" frameborder="0" width="100%" marginheight="0" marginwidth="0" scrolling="no"></iframe>

2. the page loaded into the iframe should contains all the html into an “easy retrievable” container (a div with an ID is perfect!):

1
2
3
4
5
<div id="content">
    <div style="background: red; width: 400px; height: 120px"></div>
    <div style="background: green; width: 400px; height: 300px"></div>
    <div style="background: yellow; width: 400px; height: 60px"></div>
</div>

3. on the iframe’s page “onload” event, a function will be executed to adjust its height:

1
2
3
4
5
6
7
8
function resizeIframe(iframeID) {
       
    var iframe = window.parent.document.getElementById(iframeID);
    var container = document.getElementById("content");

    iframe.style.height = container.offsetHeight + "px";
           
}

Tags: ,


Jun 03 2009

Flex 4 (Gumbo) beta released!

Category: flexDavide Zanotti @ 8:30 am

Flex 4 beta (codename: Gumbo) has been released, I just finished to read about the new major release. These are the main news:

  1. Improved compiler performance
  2. New skinning and component architecture (named Spark)
  3. Added suppurt to FXG (learn more about FXG)
  4. New states model
  5. ASDoc tool has been improved and is now possible to use ASDoc tags in mxml documents
  6. CSS has been improved to support descendant and id selectors (finally the previous missing “cascading part” of CSS has been provided!)
  7. Backwards compatibility with Flex 3

The new sdk is available on Adobe Labs

More about Gumbo here:

An Introduction to the Gumbo Component Architecture (by Deepa Subramaniam)
What’s new in Flex 4 SDK beta (by Matt Chotin)
Differences between Flex 3 and Flex 4 (by Joan Lafferty)

Tags: , , ,


May 29 2009

Jetpack: building Firefox plugin with Javascript (and jQuery)

Category: browsers,javascriptDavide Zanotti @ 8:08 am

I discovered a couple of days ago a new open source project from Mozilla labs: Jetpack.
It’s an “API set” which allows to build Firefox’s plugins by using Javascript, HTML (including new HTML 5 tags: “video” and “audio“) and CSS (oh yes, in a single word Ajax).
Jetpack is still in an early development phase and released as 0.1 version.
Here you can find the (really brief) api documentation and here some examples.
I would like to try it in the future

Tags: , , , ,


May 25 2009

Preparing for Adobe Flex 3 + AIR certification

Category: air,flexDavide Zanotti @ 12:58 am

I’m preparing for the Adobe Flex 3 + AIR certification and I would like to share two AIR applications which I’m using to study an test my Flex knowledge.
The first is pretty famous, so maybe you already know it: Tour The Flex.
It provides hundreds examples of all components available in the framework and includes Adobe reference.
The second is a real helpful app (which I discovered through Twitter), because it consist in an exam simulator (flex 3 + air). Is possible to choose between 8 different test, once a test begins a timer will show you the remaining time and at the end of test the reached score will be showed. Wrongs questions will be explained and you’ll be pointed to Adobe reference for clarifications.
The (free!) application is available here: http://software.pxldesigns.com/attest


May 20 2009

ObjectCollector: Accessing Flex’s objects by id (even dynamic generated) from anywhere

Category: flexDavide Zanotti @ 7:34 am

Ok, let me explain my last experiment…

Problem

Flex’s components have a nice id property which can be used to easily referencing object created.
All you know, that if I get the following mxml Application file:

1
2
3
4
5
6
< ?xml version="1.0" encoding="utf-8"?>
<mx:application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

    <mx:textinput id="input1" width="300" />

</mx:application>

I can then create a Script block into which I’ll point to TextInput in this way:

1
input1.text = "text dynamically added :)";

Perfect, but how can I reference dynamically created objects (components outside Application)?

Continue reading “ObjectCollector: Accessing Flex’s objects by id (even dynamic generated) from anywhere”

Tags:


« Previous PageNext Page »