Solved

OnRollover event in Movieclip

Posted on 2011-03-22
5
354 Views
Last Modified: 2012-05-11
I have a movieclip created in actionscript. I would like to add somthing to the the actionscript that would allow me to go to a specific frame in another movieclip.

something like

img_mc_container.onRollOver = function(){
images_mc.gotoAndStop(1);
}

Here is the code I am currently using which basically is a slideshow that gets the pictures out of a specific folder
var mc_container:MovieClip = this.createEmptyMovieClip("mc_container", -16384);
// highest numbered img
var highest_num:Number = 9;
var directory:String = "slideshow/";
var naming:String = "";
// create the image array
var imgArr:Array = new Array();
// for positioning purposes
var img_width:Number = 950;
var img_height:Number = 334;
var interval:Number;
function populateArr(Void):Void
{
      for (var i = 1; i<=highest_num; ++i)
      {
            var img_name:String = directory+naming+i+".gif";
            imgArr.push(img_name);
      }
}
populateArr();
var currentclip_mc:MovieClip;
var fade_rate:Number = 5;
var firstone:Number = 0;
var count:Number = 0;
function loadImg(mc:MovieClip):Void
{
      clearInterval(interval);
      count++;
      var imgobj:Object = getrange();
      var imgtoload:String = imgobj.imgtoload;
      var depth:Number = imgobj.depth;
      // Load img
      var img_mc_container:MovieClip = mc_container.createEmptyMovieClip("img_mc_container"+count, count);
      var img_load:MovieClip = img_mc_container.createEmptyMovieClip("img_load", 0);
      img_load.loadMovie(imgtoload);
      img_mc_container.currentclip_mc = mc;
      // Center on stage
      img_mc_container._x = (Stage.width-img_width)/2;
      img_mc_container._y = (Stage.height-img_height)/2;
      // hide
      img_mc_container._alpha = 0;
	
	 img_mc_container.onEnterFrame = function()
      {
            if (this.img_load.getBytesLoaded() != 0 && this.img_load.getBytesLoaded() == this.img_load.getBytesTotal())
            {
                  if (this._alpha<100)
                  {
                        this._alpha += fade_rate;
                  }
                  if (firstone>0)
                  {
                        if (this.currentclip_mc._alpha>0)
                        {
                              this.currentclip_mc._alpha -= fade_rate;
                        }
                        else if (this.currentclip_mc._alpha<=0)
                        {
                              this.currentclip_mc.removeMovieClip();
                              interval = setInterval(loadImg, 3000, this);
                              delete this.onEnterFrame;
                        }
                  }
                  else
                  {
                        if (this._alpha>=100)
                        {
                              interval = setInterval(loadImg, 3000, this);
                              firstone++;
                              delete this.onEnterFrame;
                        }
                  }
            }
      };
}
// this function just returns a number between 2 numbers, in this case 0 and myarray's length - 1
function getrange(Void):Object
{
      // length of null array   
      var min:Number = 0;
      // top of the array containing data is always [array length] - 1
      var max:Number = imgArr.length-1;
      var randnum:Number = Math.round(Math.random()*(max-min+1)+(min-.5));
      // get rid of the selection so can't do it again
      var imgtoload:String = imgArr[randnum];
      trace(imgArr[randnum]);
      imgArr.splice(randnum, 1);
      var obj:Object = ({imgtoload:imgtoload, depth:randnum});
      if (imgArr.length<1)
      {
            populateArr();
            for (var i = 0; i<imgArr.length; ++i)
            {
                  if (imgArr[i] == imgtoload)
                  {
                        imgArr.spice(i, 1);
                        break;
                  }
            }
      }
      return obj;
}
// Start App
loadImg();

Open in new window

0
Comment
Question by:techpr0
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:tomaugerdotcom
ID: 35197928
The code you list at the top of your post is the correct approach. Call gotoAndPlay() or gotoAndStop on the movieClip you wish to move the playhead on.

Can you give me some more specifics about your question? What exactly is not working, or what are you struggling with?

T
0
 

Author Comment

by:techpr0
ID: 35199583
The code is not working. When i rollover the movieclip I am expecting it to change the text in the other movie clip by going to that specific frame. but nothing happens when i rollover the movieclip
0
 

Author Comment

by:techpr0
ID: 35200965
I think i may have figured out the problem, but how would i go to a specific frame if the mouse was not over any of the flash file?
0
 
LVL 14

Accepted Solution

by:
tomaugerdotcom earned 500 total points
ID: 35201312
Since you're programming ActionScript 2, your options are limited. AS3 has an "on mouseUp outside" event that triggers even after you leave the flash area.

I wrote a blog post on how you can deal with the mouse leaving the frame in AS2 here: http://www.tomauger.com/?p=10

However I am not sure I fully understand the question. If the mouse is not inside the Flash area, how were you hoping to trigger the jump to the specific frame? Through some other HTML element or button?

T
0
 

Author Closing Comment

by:techpr0
ID: 35303984
I ended up putting a button around the edge of the flash that would take me to the correct timeline.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question