-
[RESOLVED] extra movies being attached on button click. Can't see the problem
Hi, I've been working for a while trying to fix my code and when I thought I had finally got something I find my buttons attach more clips than they're supposed to.
I hate posting a lot of code because it might seem irrelevant to other, but I need to do so because I have no clue of where the problem could be.
Here it is: it happens on attaching the exitHobb button which attaches extra clips on the top left corner of the swf.
http://web.sono.com/jpdurba for an example.
Code:
_root["subMenuButton" + 2].onPress = function():Void
{
CAT = ["FÃ*siques", "Futbol", "Tennis", "Pilota", "Cartes i jocs de taula", "Botifarra", "Backgammon", "Escacs", "Voluntariat", "Creu Roja", "Voluntari lingüÃ*stic", "Cartes al Director", "Avui", "El Periodico"];
SPA = ["FÃ*sicas", "Fútbol", "Tennis", "Pelota", "Cartas y juegos de mesa", "Botifarra", "Backgammon", "Ajedrez", "Voluntariado", "Cruz Roja", "Voluntario lingüÃ*stico", "Cartas al Director", "Avui", "El Periodico"];
ENG = ["Physical", "Football", "Tennis", "Pilota", "Card and Board games", "La Botifarra", "Backgammon", "Chess", "Volunteering", "Red Cross social events", "Catalan Linguistical Volunteer", "Press letters", "Avui", "El Periodico"];
hobbies_mc._visible = true;
for (i = 1; i <= 14; i++)
{
_root.attachMovie("HobbyTextButton" + i,"HobbyTextButton" + i,getNextHighestDepth());
_root["HobbyTextButton" + i]._x = _root.hobbies_mc["ref" + i]._x + 240;
_root["HobbyTextButton" + i]._y = _root.hobbies_mc["ref" + i]._y + 126;
if (_root.language == "catalan")
{
_root["HobbyTextButton" + i].Tex.text = CAT[i - 1];
}
else if (_root.language == "english")
{
_root["HobbyTextButton" + i].Tex.text = ENG[i - 1];
}
else if (_root.language == "spanish")
{
_root["HobbyTextButton" + i].Tex.text = SPA[i - 1];
}
_root.attachMovie("TimeExitButton","exitHobbButton_btn",getNextHighestDepth());
exitHobbButton_btn._x = hobbies_mc.exitHobbies_btn._x + 274;
exitHobbButton_btn._y = hobbies_mc.exitHobbies_btn._y + 126;
HobbyTextButton6.onRelease = function():Void
{
getURL("http://www.butinet.org", "_blank");
};
HobbyTextButton6.onRollOver = function():Void
{
_root.attachMovie("Buti_Img","Buti_Img",getNextHighestDepth());
Buti_Img._x = _root.hobbies_mc.ref6._x + 330;
Buti_Img._y = _root.hobbies_mc.ref6._y + 120;
};
HobbyTextButton6.onRollOut = function():Void
{
Buti_Img.removeMovieClip();
};
HobbyTextButton7.onRelease = function():Void
{
getURL("http://www.netgammon.com", "_blank");
};
HobbyTextButton13.onRollOver = function():Void
{
_root.attachMovie("avui_btn","avui_btn",getNextHighestDepth());
avui_btn._x = _root.hobbies_mc.ref13._x + 306;
avui_btn._y = _root.hobbies_mc.ref13._y + 126;
if (_root.language == "english")
{
_root.attachMovie("TradAvui_btn","TradAvui_btn",getNextHighestDepth());
TradAvui_btn._x = _root.hobbies_mc.ref13._x + 312;
TradAvui_btn._y = _root.hobbies_mc.ref13._y + 144;
}
periodico1_btn.removeMovieClip();
periodico2_btn.removeMovieClip();
periodico3_btn.removeMovieClip();
periodico4_btn.removeMovieClip();
avui_btn.Tex.text = "12/10/2012";
TradAvui_btn.Tex.text = "Translation";
avui_btn.onPress = function():Void
{
getURL("http://www.elpuntavui.cat/noticia/article/-/-/462641.html", "_blank");
};
TradAvui_btn.onPress = function():Void
{
_root.attachMovie("tradAvui_mc","tradAvui_mc",getNextHighestDepth());
tradAvui_mc._x = 400;
tradAvui_mc._y = 240;
tradAvui_mc.onPress = function()
{
startDrag(this);
};
tradAvui_mc.onRelease = function()
{
stopDrag();
_root.attachMovie("TimeExitButton","exitTradAvui_btn",_root.getNextHighestDepth());
exitTradAvui_btn._x = _root.tradAvui_mc._x + 566;
exitTradAvui_btn._y = _root.tradAvui_mc._y + 5;
exitTradAvui_btn.onPress = function():Void
{
tradAvui_mc.swapDepths(0);
tradAvui_mc.removeMovieClip();
exitTradAvui_btn.swapDepths(0);
exitTradAvui_btn.removeMovieClip();
_root["subMenuButton" + 13].enabled = true;
};
};
};
};
var dates:Array = ["01/07/2013", "03/07/2013", "26/07/2013", "28/09/2013"];
HobbyTextButton14.onRollOver = function():Void
{
for (j = 1; j <= 4; j++)
{
_root.attachMovie("periodico" + j + "_btn","periodico" + j + "_btn",getNextHighestDepth());
_root["periodico" + j + "_btn"]._x = _root.hobbies_mc.ref14._x + 306;
//_root["periodico" + j + "_btn"]._y = _root.hobbies_mc.ref14._y + 120+(22*i);
_root["periodico" + j + "_btn"].Tex.text = dates[j - 1];
avui_btn.removeMovieClip();
TradAvui_btn.removeMovieClip();
}
periodico1_btn._y = _root.hobbies_mc.ref13._y + 126;
periodico2_btn._y = _root.hobbies_mc.ref13._y + 144;
periodico3_btn._y = _root.hobbies_mc.ref13._y + 162;
periodico4_btn._y = _root.hobbies_mc.ref13._y + 180;
periodico1_btn.onRelease = function():Void
{
getURL("http://www.elperiodico.cat/ca/cartas/entre-tots/vehicles-amb-xofer-conveni-sense-aplicar/77926.shtml", "_blank");
};
periodico2_btn.onRelease = function():Void
{
getURL("http://www.elperiodico.cat/ca/cartas/entre-tots/tv-3-gran-dictat/78524.shtml", "_blank");
};
periodico3_btn.onRelease = function():Void
{
getURL("http://www.elperiodico.cat/ca/cartas/entre-tots/seguretat-viaria-hem-millorar-formacio/80548.shtml", "_blank");
};
periodico4_btn.onRelease = function():Void
{
getURL("http://www.elperiodico.cat/ca/cartas/entre-tots/porto-passaport-sobre-pero-per-raons-molt-diferents-les-sanchez-camacho/85704.shtml", "_blank");
};
};
exitHobbButton_btn.onRelease = function()
{
hobbies_mc._visible = false;
Buti_Img.removeMovieClip();
tradAvui_mc.removeMovieClip();
exitTradAvui_btn.removeMovieClip();
periodico1btn.removeMovieClip();
periodico2_btn.removeMovieClip();
periodico3_btn.removeMovieClip();
periodico4_btn.removeMovieClip();
exitHobbButton_btn.removeMovieClip();
for (i = 1; i <= 14; i++)
{
_root["HobbyTextButton" + i].removeMovieClip();
_root["subMenuButton" + 2].enabled = true;
}
};
}
_root.hobbies_mc.onRollOut = function()
{
avui_btn.removeMovieClip();
TradAvui_btn.removeMovieClip();
periodico1_btn.removeMovieClip();
periodico2_btn.removeMovieClip();
periodico3_btn.removeMovieClip();
periodico4_btn.removeMovieClip();
};
};
-
.
Hi Cap,
You keep attaching things to the _root, try attaching them to the movieclip you desire instead,
instead of
PHP Code:
_root.attachMovie("TimeExitButton","exitHobbButton_btn",getNextHighestDepth()); exitHobbButton_btn._x = hobbies_mc.exitHobbies_btn._x + 274; exitHobbButton_btn._y = hobbies_mc.exitHobbies_btn._y + 126;
try
PHP Code:
hobbies_mc.attachMovie("TimeExitButton","exitHobbButton_btn",1); hobbies_mc.exitHobbButton_btn._x = hobbies_mc._width - 10; hobbies_mc.exitHobbButton_btn._y = 5;
and for the exit button code, change it to
PHP Code:
exitHobbButton_btn.onRelease = function() { hobbies_mc._visible = false; Buti_Img.removeMovieClip(); tradAvui_mc.removeMovieClip(); exitTradAvui_btn.removeMovieClip(); periodico1btn.removeMovieClip(); periodico2_btn.removeMovieClip(); periodico3_btn.removeMovieClip(); periodico4_btn.removeMovieClip(); hobbies_mc.exitHobbButton_btn.removeMovieClip(); for (i = 1; i <= 14; i++) { _root["HobbyTextButton" + i].removeMovieClip(); _root["subMenuButton" + 2].enabled = true; } };
but I still think that if you are going to have the movieclip set as invisible from the start, why not just put the buttons and tings directly into the movieclip itself, save a lot of hassle.
Last edited by fruitbeard; 10-01-2013 at 09:00 AM.
-
.
Hi,
Sorry, that should be
PHP Code:
hobbies_mc.exitHobbButton_btn.onRelease = function()
You could always make separate swf files and load them in, make things easier to change and keep code blocks smaller and less messy.
Last edited by fruitbeard; 10-01-2013 at 09:14 AM.
-
Hi, FruitBeard, thanks for the reply once more. I am redesigning my site from scratch and am going to do things one step at a time now. I am redesingning it because it turned out that the filtering colour of my boxes can be achieved easily with no need to convert that to a movieClip and, hopefully I will be able to control everything I do easier now.
So, if you won't mind my asking; I'm starting off with my resumee clip I'm attaching via loadMovie just like the chat you had checked and improved for me, but I'm facing problems even though I am copying the code you used in the chat to unload itself on exiting with the button.
That is: this is what I have in the main swf:
Code:
_root["subMenuButton" + 1].onPress = function():Void
{
_root.createEmptyMovieClip("contenidor_mc",_root.getNextHighestDepth());
contenidor_mc._x = 1050;
contenidor_mc._y = -72;
loadMovie("picResumee.swf",contenidor_mc);
};
and this is what I have in the loaded swf. It loads data from a loadVars and I've tried to delete it but I guess I still need a lot to know because nothing is happening:
Code:
_root.exitButton_btn.onRelease = function()
{
_root.contenidor_mc.unloadMovie();
_root["subMenuButton" + 1].enabled = true;
};
Could you help me solve this, please? I bet the rest of the clips I will be able to handle by myself since it will be the same method.
I'm adding more code, since maybe I need to place the call somewhere else:
Code:
// This will be the starting position of the textbox
var starting_ypos:Number;
// This will be has fast the text box will scroll
var scroll_speed:Number = .5;
// Make a load vars object
my_data = new LoadVars();
// Make my on load function
my_data.onLoad = function()
{
// Fix the double space issue
var my_text = unescape(this.content).split("\r\n");
my_text = my_text.join("\n");
my_text = my_text.split("\r");
my_text = my_text.join("\n");
// Set the text in the text box
scroll_text.htmlText = my_text;
// Set the autosize
scroll_text.autoSize = true;
// Set the starting_ypos
starting_ypos = scroll_text._y;
};
// Load the external text file
if (_root.language == "catalan")
{
my_data.load("cat_text.txt");
exitButton.onRelease = function():Void
{
removeMovieClip(this);
this["subMenuButton" + 1].enabled = true;
};
}
else if (Object(this).language == "english")
{
my_data.load("my_text.txt");
}
else if (Object(_root).language == "spanish")
{
my_data.load("cast_text.txt");
}
// Start the scrolling
this.onEnterFrame = function()
{
// Check for hit test with the mask and the mouse
if (!mask_mc.hitTest(_root._xmouse, _root._ymouse))
{
// Check to see if we are in the mask
if (mask_mc.hitTest(scroll_text))
{
// Move the textbox
scroll_text._y -= scroll_speed;
}
else
{
// Reset the text box
delete onEnterFrame;
}
}
};
_root.exitButton_btn.onRelease = function()
{
_root.contenidor_mc.unloadMovie();
_root["subMenuButton" + 1].enabled = true;
};
-
.
Hi Cap,
If I were you I would use movieClipLoader(); and create the empty movie clips beforehand, like so
PHP Code:
// *** create empty clips first _root.createEmptyMovieClip("contenidor_mc",_root.getNextHighestDepth()); contenidor_mc._x = 1050; contenidor_mc._y = -72;
// declare reusable movie loader MyLoader = new MovieClipLoader(); MyListen = new Object(); MyLoader.addListener(MyListen); MyLoader.onLoadStart = function(Target) { // *** movie started load //myLoadText.text = ""; }; MyLoader.onLoadProgress = function(Target, LoadBytes, TotalBytes) { // *** movie load progress //Percent = Math.round((LoadBytes / TotalBytes) * 100); //myLoadText.text = Percent + "%"; }; MyLoader.onLoadComplete = function(Target) { // *** movie now loaded //myLoadText.text = 0; }; MyLoader.onLoadInit = function(Target) { // *** movie loaded, instigate code };
_root["subMenuButton" + 1].onPress = function():Void { this.enabled = false; MyLoader.loadClip("picResumee.swf",contenidor_mc); };
and put your exit buttons inside your external swf files and use the commands from within, like so
PHP Code:
exitButton_btn.onRelease = function() { unloadMovie(_root.contenidor_mc); _root["subMenuButton" + 1].enabled = true; };
-
starting over
Hi, Fruitbeard,
just did as I believed you mentioned and placed this dummy_mc underneath my pic and text layers in the loaded swf, but I must have missed something because it is not working.
I placed this code and made the rolling text unselectable as well.:
Code:
Object(this).dummy_mc.onPress = function():Void{
startDrag(this._parent);
}
Object(this).dummy_mc.onPress = function():Void{
stopDrag();
}
but, the part where I'm lost is getting rid of listeners...
this is all the code in the swf:
Code:
var starting_ypos:Number;
var scroll_speed:Number = .5;
my_data = new LoadVars();
my_data.onLoad = function()
{
var my_text = unescape(this.content).split("\r\n");
my_text = my_text.join("\n");
my_text = my_text.split("\r");
my_text = my_text.join("\n");
scroll_text.htmlText = my_text;
scroll_text.autoSize = true;
starting_ypos = scroll_text._y;
};
if (_root.language == "catalan")
{
my_data.load("cat_text.txt");
}
else if (Object(this).language == "english")
{
my_data.load("my_text.txt");
}
else if (Object(_root).language == "spanish")
{
my_data.load("cast_text.txt");
}
this.onEnterFrame = function()
{
if (!mask_mc.hitTest(_root._xmouse, _root._ymouse))
{
if (mask_mc.hitTest(scroll_text))
{
scroll_text._y -= scroll_speed;
}
else
{
delete onEnterFrame;
}
}
};
;
-
.
Hi Cap,
Mail me your new files and I will try to sort it out for you, I will comment out where I changed etc etc.
All files that you are messing with, so index.fla and the new resumee clip.fla
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
|