Skip to main content
Known Participant
January 18, 2010
Question

Calling a javascript function invinite loop - Help

  • January 18, 2010
  • 1 reply
  • 1718 views

I'm trying to get AS to call a javascript function. This is working fine. As a test a changed the js function to trigger an alert.

This works and the alert comes up but it forms a loop and I'm not sure you to get it to stop repeating the alert.

You can see what I mean at http://test.justsandymedia.com/working_15_01_10/working_15_01_10v5_1.html

---------------WARNING THIS LINK WILL OPEN AN SWF WHICH WILL CREATE A LOOP WHEN IT CLOSES. YOU WILL HAVE TO FORCE QUIT YOUR BROWSER SO MAKE SURE THAT YOU DON'T HAVE ANYTHING IMPORTANT UNSAVED OPEN----------

Sorry for the caps but I want to make sure everyone knows what will happen.

Here is my AS

// Create a movie clip instance.
import flash.external.*;

var my_fmt:TextFormat = new TextFormat();
my_fmt.color = _root.textcolor;
my_fmt.size = _root.textsize;
my_fmt.font = _root.textfont;
closebut_mc.closetext_txt.text = _root.closetext;
adbut_mc.adtext_txt.text = _root.adtext;
closebut_mc.closetext_txt.setTextFormat(my_fmt);
adbut_mc.adtext_txt.setTextFormat(my_fmt);


import flash.geom.ColorTransform;
bckgrnd_mc.onEnterFrame = function() {
    var colorTransform:ColorTransform = this.transform.colorTransform;
    colorTransform.rgb = _root.bgcolor;
    this.transform.colorTransform = colorTransform;
}

this.createEmptyMovieClip("img1_mc", 10);
var mcl_obj:Object = new Object();
mcl_obj.onLoadInit = function (target_mc:MovieClip):Void {
    function closebanner(){
        target_mc.onEnterFrame = function() {
        target_mc._y += 10;
        bckgrnd_mc._y += 10;
        click_btn._y = 150;
        closebut_mc._y += 10;
        adbut_mc._y += 10;
        ExternalInterface.call("pgcover");
        stop();
        };
       
}
    target_mc._y = 110;
    target_mc._x = 94;
    target_mc.onEnterFrame = function() {
        target_mc._y -= 10; // decrease current _y position by 10 pixels
        if (target_mc._y <= 0) {
            target_mc._y = 0;
            delete target_mc.onEnterFrame;
            setTimeout(closebanner,_root.screentime); //5 seconds
            setTimeout(closefade,_root.screentime); //5 seconds
            stop();
        }
    };
};
var img_mcl:MovieClipLoader = new MovieClipLoader();
img_mcl.addListener(mcl_obj);
// Load an image into the movie clip
//_global.bannerImage is a global var set to be a var which is passed from JS on html page
img_mcl.loadClip(_root.bannerImage, img1_mc);



_root.closebut_mc.closebut_btn.onRelease = function(){
    img1_mc._y = 110;
    bckgrnd_mc._y = 150;
    click_btn._y = 150;
    closebut_mc._y = 150;
    adbut_mc._y = 150;
    ExternalInterface.call("pgcover");
}

_root.adbut_mc.adbut_btn.onRelease = function(){
    getURL (_root.adclicktag, "_blank");
}

_root.closebut_mc.swapDepths(getNextHighestDepth());
_root.adbut_mc.swapDepths(getNextHighestDepth());

click_btn.onRelease = function(){
    getURL (_root.clicktag, "_blank");
}

//getURL("javascript:displayPost(" + postId + "," + feedId +")");
// the above line of code(74) may also be used possibly to call javascript functions where displayPost
// is the javascript function to be called.


And here is my html/js

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>working_15_01_10v5_1</title>
</head>
<body bgcolor="#FFFFFF">
<!--url's used in the movie-->
<!--text used in the movie-->
<!-- saved from url=(0013)about:internet -->

<script type="text/javascript">
function pgcover() {
alert ('pgcover');
}
</script>

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="1015" height="110" id="working_15_01_10v5_1" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="working_15_01_10v5_1.swf" /><param name="quality" value="high" />

<PARAM NAME="FlashVars" VALUE="bannerImage=banner2%2Epng&clicktag=http://www.building.co.uk&bgcolor=#ff0000&screentime=5000&textcolor=0xFFDDFF&textsize=15&textfont=Verdana&closetext=close&adtext=advertise here&adclicktag=http://www.building.co.uk/hybrid.asp?navcode=2437">

<param name="wmode" value="transparent" /><param name="bgcolor" value="#FFFFFF" />
<embed src="working_15_01_10v5_1.swf" quality="high" wmode="transparent" bgcolor="#FFFFFF" width="1015" height="110" name="working_15_01_10v5_1" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="bannerImage=banner2%2Epng&clicktag=http://www.building.co.uk&bgcolor=0xff0000&screentime=5000&textcolor=0xFFDDFF&textsize=15&textfont=Verdana&closetext=close&adtext=advertise here&adclicktag=http://www.building.co.uk/hybrid.asp?navcode=2437" />
</object>
</body>
</html>

Any help would be great, thanks.

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
January 18, 2010

1.  never nest named functions.  ie, remove closebanner() from onLoadInit().

2.  remove the onEnterFrame loops.  (what are you trying to do?)

SproglegAuthor
Known Participant
January 18, 2010

I nested the closebanner function as I couldn't find another way to get it to work. How can retain the functionality with it un-nested?

If I remove the onenterframe loops then the entire swf will fail.

In the simplest terms I'm trying to get it to do this http://test.justsandymedia.com/working_15_01_10/working_15_01_10v5.html

But when it has finished I want to use js to swap in an empty swf so that the content of the original doesnt get in the way.(I'll be honest, I'm being told this from a web dev, who doesn't know anything about flash and I don't know much about js).

kglad
Community Expert
Community Expert
January 18, 2010

i don't want to check your link if it's going to crash/freeze my browser.

pass the load-target to your nested function.

addendum:  you're not even using that moviecliploader in the code you're showing.