-
[F8] Events dont run when JPG is loaded into MC
Ok, I'm trying to make a "picture viewer" type thing where I can load any number of photos from a text file, and then it will display them. Once they are display, I want events to happen when you roll you mouse over them. Now, when I was getting things running, I was able to get this far. Draw my own box, and have the events run. Here, take a look.
PHP Code:
//CONSTANTS//
var THUMB_SPACE:Number = 110;
var PIC_WIDTH:Number = 100;
var PIC_HEIGHT:Number = 100;
var FADE_IN:Boolean = true;
var ALPHA_SPEED:Number = 30;
var TEXT_BOX_WIDTH:Number = 200;
var TEXT_BOX_HEIGHT:Number = 100;
var my_lv:LoadVars = new LoadVars();
var pics_ar:Array = new Array();
var names_ar:Array = new Array();
var hasLoaded:Boolean = false;
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(this);
var level:Number = 1;
var rootMC:MovieClip;
var isOnABox:Boolean = false;
setUpEvents = function(num:Number, cont:MovieClip):Void {
for (var i = 0; i<num; i++) {
cont["mc"+i].onRollOver = createTextBox;
cont["mc"+i].onRollOut = function():Void {
isOnABox = false;
};
}
};
//END VARIABLES//
my_lv.onLoad = function(success:Boolean) {
if (success) {
trace("success");
var mypics:String = my_lv.mypics;
var mynames:String = my_lv.mynames;
pics_ar = mypics.split("~!~");
names_ar = mynames.split("~!~");
trace(pics_ar);
trace(names_ar);
hasLoaded = true;
initi((pics_ar.length));
} else {
trace("failure");
}
};
loadTheVars = function(file:String):Void {
my_lv.load(file);
};
createTextBox = function():Void {
isOnABox = true;
Mouse.hide();
var box_mc = _root.createEmptyMovieClip("box_mc"+level, _root.getNextHighestDepth());
rootMC = box_mc;
level++;
if (FADE_IN==true){
box_mc._alpha = 0;
}
var xmouse = _root._xmouse;
var ymouse = _root._ymouse;
box_mc.beginFill(0xFF0000);
box_mc.lineStyle(3, 0x000000, 100, true, "none", "none");
box_mc.moveTo(0, 0);
box_mc.lineTo(TEXT_BOX_WIDTH, 0);
box_mc.lineStyle(2, 0x000000, 100, true, "none", "square");
box_mc.lineTo(TEXT_BOX_WIDTH, TEXT_BOX_HEIGHT);
box_mc.lineTo(0, TEXT_BOX_HEIGHT);
box_mc.lineStyle(3, 0x000000, 100, true, "none", "none");
box_mc.lineTo(0, 0);
box_mc.endFill();
box_mc._x = xmouse+3;
box_mc._y = ymouse+3;
xx = 0;
yy = 0;
thewidth = 200;
theheight = 100;
box_mc.createTextField("mytext_box",
_root.getNextHighestDepth(), xx, yy, thewidth, theheight);
box_mc.mytext_box.multiline = true;
box_mc.mytext_box.selectable = false;
box_mc.mytext_box.border = false;
box_mc.mytext_box.wordWrap = true;
var fmt:TextFormat = new TextFormat();
fmt.color = 0x000000;
box_mc.mytext_box.text = "Work you!";
box_mc.mytext_box.setTextFormat(fmt);
box_mc.onEnterFrame = function():Void {
if (isOnABox==true) {
if (FADE_IN==true && this._alpha<100) {
//trace('fading in');
this._alpha+=ALPHA_SPEED;
} else if (FADE_IN==false) {
//trace("not fading in");
}
this._x += 3+(_root._xmouse - this._x)/2;
this._y += 3+(_root._ymouse - this._y)/2;
} else {
Mouse.show();
this._x += 3+(_root._xmouse - this._x)/2;
this._y += 3+(_root._ymouse - this._y)/2;
if (FADE_IN==true) {
//trace("fading out");
if (this._alpha>0) {
this._alpha-=ALPHA_SPEED;
this.mytext_box._alpha-=ALPHA_SPEED;
} else {
this.removeMovieClip();
this.mytext_box.removeTextField();
}
} else {
//trace("not fading out");
this.removeMovieClip();
this.mytext_box.removeTextField();
}
}
};
};
randomColor = function():Number {
return Math.floor(Math.random()*0xFFFFFF);
};
createShapes = function(num:Number, cont:MovieClip):Void {
for (var i=0; i<num; i++) {
cont.createEmptyMovieClip("mc"+i, i+1);
cont["mc"+i].beginFill(randomColor());
cont["mc"+i].moveTo(0,0);
cont["mc"+i].lineTo(0,PIC_HEIGHT);
cont["mc"+i].lineTo(PIC_WIDTH,PIC_HEIGHT);
cont["mc"+i].lineTo(PIC_WIDTH,0);
cont["mc"+i].lineTo(0,0);
cont["mc"+i].endFill();
cont["mc"+i]._x = 30 + (THUMB_SPACE*i);
cont["mc"+i]._y = 30;
//mcLoader.loadClip(pics_ar[i], cont["mc"+i]);
cont["mc"+i].id = i;
}
setUpEvents(num, cont);
};
initi = function(num:Number):Void {
var _mc:MovieClip = _root.createEmptyMovieClip("main", 999);
createShapes(num, _mc);
};
loadTheVars("pictures.txt");
Now on line 141, I have my problem. It is commented out, and it is the //mcLoader.loadClip(pics_ar[i], cont["mc"+i]); When I take out the comment, and make it actual code, the jpg's load fine, but nothing happens when I roll over them! ARGHH! Help please! Thanks.
-
Maybe try something like this...
Code:
createShapes = function (num:Number, cont:MovieClip) {
for (var i = 0; i < num; i++) {
cont.createEmptyMovieClip("mc" + i, i + 1);
cont["mc" + i].createEmptyMovieClip("holder", 1);
cont["mc" + i].beginFill(randomColor());
cont["mc" + i].moveTo(0, 0);
cont["mc" + i].lineTo(0, PIC_HEIGHT);
cont["mc" + i].lineTo(PIC_WIDTH, PIC_HEIGHT);
cont["mc" + i].lineTo(PIC_WIDTH, 0);
cont["mc" + i].lineTo(0, 0);
cont["mc" + i].endFill();
cont["mc" + i]._x = 30 + (THUMB_SPACE * i);
cont["mc" + i]._y = 30;
mcLoader.loadClip(pics_ar[i], cont["mc" + i].holder);
cont["mc" + i].id = i;
}
setUpEvents(num, cont);
};
-
Awesome dude. It works. Don't know why my original didn't work and that one does, but whatever, I'll take it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|