Skip to main content
Known Participant
July 14, 2009
Answered

Doesn't Autoplay + Bugs

  • July 14, 2009
  • 1 reply
  • 802 views

I have embedded a swf inside my html file, but it doesn't seem to play once it has loaded. Instead, you have to click on it to start up the movie. I am wondering if there is a way to fix this? Does it have something to do with the HTML code?

In addition, I've noticed that sometimes the .swf will freeze up or stutter. For instance, sometimes the tweens do not finish completely. Could this be because of my AS3 coding?

Link to website:
http://www.sfu.ca/~jca41/stuph/ny/template.html

Link to .swf
http://www.sfu.ca/~jca41/stuph/ny/slideShow07.swf

HTML CODE:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="360" height="730" id="slideShow07" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="slideShow07.swf" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" />     
<embed src="slideShow07.swf" quality="best" bgcolor="#ffffff" width="360" height="730" name="slideShow07" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />


AS3 CODE:

import fl.transitions.Tween;
import fl.transitions.easing.*;


////////////////////////////
/// Variables to Change ///
var imgArray:Array = new Array("img01", "img02", "img03", "img04", "img05");
var txtArray:Array = new Array("txt01", "txt02", "txt03", "txt04", "txt05");
var tween1Speed:Number = 1;  //1
var tween2Speed:Number = 20;  //20
/// End of Variables ///
///////////////////////


var imgDefArray:Array = new Array();
var txtDefArray:Array = new Array();
var iSlideShow:int = 0;
var iLoadChild:int = 0;
var tempI:int;

var newYellowBar:yellowBar = new yellowBar();
addChild(newYellowBar);
newYellowBar.x = -50;

var timer1Delay:Number = tween2Speed * 0.70 * 1000;
var timer1:Timer = new Timer(0, 0);
timer1.addEventListener(TimerEvent.TIMER, slideShow1);

var timer2Delay:Number = tween1Speed * 1000;
var timer2:Timer = new Timer(timer2Delay, 0);
timer2.addEventListener(TimerEvent.TIMER, slideShow2);


mc.addEventListener(Event.ACTIVATE, loadChild);


function loadChild(e:Event){
     timer1.start();
     for (iLoadChild = 0; iLoadChild < imgArray.length; iLoadChild++) {
          var imgDef:Class = getDefinitionByName(imgArray[iLoadChild]) as Class;
          var txtDef:Class = getDefinitionByName(txtArray[iLoadChild]) as Class;                                                                      
          var img:MovieClip = new imgDef();
          var txt:MovieClip = new txtDef();     
          imgDefArray[iLoadChild] = img;
          txtDefArray[iLoadChild] = txt;
          addChild(imgDefArray[iLoadChild]);
          addChild(txtDefArray[iLoadChild]);
          imgDefArray[iLoadChild].x = 800;
          imgDefArray[iLoadChild].y = 800;
          txtDefArray[iLoadChild].x = 800;
          txtDefArray[iLoadChild].y = 800;
     }
}


function slideShow1(e:TimerEvent):void {
     timer1.delay = timer1Delay; 
     timer1.stop();
     timer2.start();

     setChildIndex(imgDefArray[iSlideShow], numChildren - 1);
     setChildIndex(txtDefArray[iSlideShow], numChildren - 1);
     setChildIndex(newYellowBar, numChildren - 1);     
          
     imgDefArray[iSlideShow].x = 600;
     imgDefArray[iSlideShow].y = 320;
     txtDefArray[iSlideShow].x = 600;
     txtDefArray[iSlideShow].y = 600;
     newYellowBar.x = 600;
     newYellowBar.y = 320;

     new Tween(imgDefArray[iSlideShow], "x", None.easeInOut, 360, 0, tween1Speed, true);
     new Tween(txtDefArray[iSlideShow], "x", None.easeInOut, 720, 360, tween1Speed, true);
     new Tween(newYellowBar, "x", None.easeInOut, 360, 0, tween1Speed, true);
     
     tempI = iSlideShow - 1;
     if (tempI == -1){
          tempI = txtDefArray.length - 1;
     }
     
     setChildIndex(txtDefArray[tempI], numChildren - 1);
     txtDefArray[tempI].x = 360;
     txtDefArray[tempI].y = 600;
     new Tween(txtDefArray[tempI], "x", None.easeInOut, 360, 0, tween1Speed, true);
}


function slideShow2(e:TimerEvent):void {
     timer1.start();
     timer2.stop();
     
     setChildIndex(imgDefArray[iSlideShow], numChildren - 1);
     setChildIndex(txtDefArray[iSlideShow], numChildren - 1);
          
     imgDefArray[iSlideShow].x = 0;
     imgDefArray[iSlideShow].y = 320;

     new Tween(imgDefArray[iSlideShow], "x", None.easeInOut, 0, -1000, tween2Speed, true);
     
     if (iSlideShow == imgArray.length -1) {
          iSlideShow = -1;
     }
     iSlideShow++;
}

This topic has been closed for replies.
Correct answer Craig Grummitt

Haha.. Nevermind. I figured it out, but I want to make sure that I am doing it the proper way.

loadChild();

function loadChild() {

     ......

}


yes that's the correct way to call a function.

1 reply

Craig Grummitt
Inspiring
July 14, 2009

Problem 1: 

you have to click on it to start up the movie

The app is waiting for you to click on it, because you've asked it to with :

mc.addEventListener(Event.ACTIVATE, loadChild);

This line specifies that loadChild doesn't get called until mc has focus.

Problem 2:

sometimes the tweens do not finish completely

If you don't retain a reference to your tweens they can get garbage collected, and this is even more likely if you're doing memory intensive operations like you are doing such as loading large images.

So if you're using 'Tween' you need to declare a persistent variable and then set your tween to it.

eg.

//in your variable declarations

var tween1:Tween;

//and then later when you declare your tween:

tween1=new Tween(etc...

Known Participant
July 15, 2009

How would I get my function loadChild to execute without the event listener. I always thought that the only way to get things to execute is through event listeners. (Sorry, I am new to ActionScript).

I added the var tween1:tween and it worked beautifully

Known Participant
July 15, 2009

Haha.. Nevermind. I figured it out, but I want to make sure that I am doing it the proper way.

loadChild();

function loadChild() {

     ......

}