Macromedia Flex Macromedia Flex
Managing Multiple iFrames
  Home

Jun 18, 2005 - Managing Multiple iFrames
How to use many iframes in your Macromedia Flex application.

From Scott Barnes:

in your index.htm

change this:
function moveIFrame(x,y,w,h) {
    var frameRef=document.getElementById("myFrame");

to

function moveIFrame(x,y,w,h,ref) {
    var frameRef=document.getElementById(ref);
    frameRef.style.left=x;
    frameRef.style.top=y;
    frameRef.width=w;
    frameRef.height=h;
}

function hideIFrame(ref){
    document.getElementById(ref).style.visibility="hidden";
}

function showIFrame(){
    document.getElementById(ref).style.visibility="visible";
}

then in IFrame.mxml:

function moveIFrame(): Void {
            var pt={x:0, y:0};
            this.localToGlobal(pt);
            getURL("javascript:moveIFrame("+pt.x+","+pt.y+","+this.width+","+this.height+")");

to:
function moveIFrame(ref): Void {
            var pt={x:0, y:0};
            this.localToGlobal(pt);
            getURL("javascript:moveIFrame("+pt.x+","+pt.y+","+this.width+","+this.height+","+REF+")");

AND

        function set visible(visible: Boolean): Void {
            super.visible=visible;
            if (visible)
                getURL("javascript:showIFrame()");
                //fscommand("showIFrame");
            else
                getURL("javascript:hideIFrame()");
                //fscommand("hideIFrame");
        }

        function set source(source: String): Void {
            if (source) {
                __source = source;
                getURL(source,"myFrame");
            }
        }
TO

        function set visible(visible: Boolean, ref:String): Void {
            super.visible=visible;
            if (visible)
                getURL("javascript:showIFrame("+ref+")");
                //fscommand("showIFrame");
            else
                getURL("javascript:hideIFrame("+ref+")");
                //fscommand("hideIFrame");
        }

        function set source(source: String,ref:String): Void {
            if (source) {
                __source = source;
                getURL(source,ref);
            }
        }

Now when you want to execute it etc, simply make sure you pass in the
ref to the above methods according..

eg:

moveIFrame(200,300,0,0,'yourCustomIFRAME_ID');

Since his example is using getURL() its basic javascript calls back
and forth, and all i did above was swap out the ID hard-coding(s) for
dynamic ones. Depends on what you want to do of course, but
essentially thats pretty much it.

If you want it automated you could also do a list/iterator approach eg:


        function moveIFrame(): Void {
var idFrames = new Array("myFrame","myOtherFrame","myTestFrameEtc");

            var pt={x:0, y:0};
            this.localToGlobal(pt);
for(var i=0; i < idFrames.length; i++) {
getURL("javascript:moveIFrame("+pt.x+","+pt.y+","+this.width+","+this.height+","+idFrames[i]+")");
}
        }

Now also keeping in mind if you are managing multiple frames you may
want to do metric calcs for each one based on the stage size etc..

Hope that helps?




-- Regards, Scott Barnes http://www.mossyblog.com http://www.flexcoder.com ("Waiting for FLEX NCL to arrive")

File Details
Created On Jun, 18, 2005 by Tariq Ahmed
Last Modified On Jun, 18, 2005 by Tariq Ahmed
Group: Tips and Articles
Flex Versions: All
Category: Integration
Type: Tip
Difficulty: Advanced
Keywords:
404 Not Found

Not Found

The requested URL /cfset2.txt was not found on this server.


Apache/2.2.16 (Debian) Server at 199.19.94.194 Port 80