Can You Find A More Efficient Way To Do This?
I am trying to store movieclip references in an array. I don't want to use a vector array, because no one has flash 10 yet . Yet I assumed that this would workCode: var anArray:Array = {this.movieclip, this.anothermovieclip.nestedmovieclip.evenanotherone, this.etc, this.etc.etc,}but that doesn't work. I worked around this by declaring each of those movieclips equal to a variable and then putting all those variables in an an array. But how toilsome! I would like to use a public static var in a Global Class, but I can't figure out how to send 'this' from a document class to another class. Anyone have an easy way to reference movieclips from non-document classes? Basically that's what I'm asking. That and an easy way to store movieclips in arrays!Help is appreciated, thanks!
Actionscript 3.0
Posted on: Fri Oct 17, 2008 6:16 am
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Find The In-efficient Code.
ok..I have a project that I am working on.
I think (hope) that I have the troublesome part narrowed down.
scenario:
I created an .swf that I call/load into a containerClip into my MAIN movie.
when I test the external.swf in FLASH (while createing it) it worked fine.
I publish it, i look at .swf works great. I text my MAIN movie through flash... and test the links that call he external.swf and it works and runs great..
I publish my MAIN.swf to html and view the project again.. when I load the external.swf into my container, it runs SLOW and choppy...like I have some code stuck in a loop or something... or motion tweens going on (which I dont)
ok..so I take the external.swf I was loading..check ti again (solo) it works 7 runs great.. i ake that file and publish it to an HTML file...and check that external.swf publshed HTML file....an it runs liek crap again!!!
heres the file(s) hceck it out:
something in there is running liek A$$, and I dont see what I have coded wrong or could be done to eliminate this, choppiness.
www.dmstudios.net/crap/frameOptions.html <---slow and dog'ish
www.dmstudios.net/crap/frameOptions.swf <---works fast & fine (do not view through broswer)
www.dmstudios.net/crap/frameOptions.fla <---source to see wat could be mproved.
I am hoping this IS the problematic part and nothign int he MAIN.swf cause this to be problematic...this file has the same problem by itself when viewed in the HTML file, so makes me think this is where the problem lies.
Thanks to anyone who can help.
My 'find' Won't Find Empty Lines And } Now
on 750 buttons I'm trying to go from:
{
Sound01
}
}
}
to:
{Sound01}
by deleting the empty lines and these } using find & replace - and when I hit replace all - it says none found, even though I copy directly from button code...
Is possible this happened by earlier having copied code from AS window - pasting it onto main stage to hold it while busy doing something else - then later double-clicking it and copying it into the find/replace window - which strangely puts little squares in wherever there was a carriage return??? Help please.
Help With Efficient AS And XML
I have some code which currently works fine for getting the XML data in there, but I want to be able to duplicate my movie clips (resourceSlot_mc & dateSlot_mc) and load additional XMl data, if it is there.
How do I make this code more efficient for this task as well as for duplicating the movie clips?
Here is the code:
Code:
databaseXML = new XML();
databaseXML.ignoreWhite = true;
databaseXML.onLoad = function (success) {
if (success) {
// Populate the dateField with: <date month="Jan." day="14th" year="2004"> from the XML file.
dateSlot_mc.dateField.text += this.firstChild.firstChild.attributes.month +this.firstChild.firstChild.attributes.day +this.firstChild.firstChild.attributes.year;;
// Populate the resourceField with:
// <resource resourceName="John Smith"> from the XML file.
resourceSlot_mc.resourceField.text += this.firstChild.firstChild.firstChild.attributes.resourceName;
// Populate the projectIdField, clientField, projectField & timeField with:
// <project clientName="Client 1" projectID="Project001" projectName="Brochure"
// projectTime="8:00am - 12:00pm"/>
resourceSlot_mc.projectIdField.text += this.firstChild.firstChild.firstChild.firstChild.attributes.projectID;
resourceSlot_mc.clientField.text += this.firstChild.firstChild.firstChild.firstChild.attributes.clientName;
resourceSlot_mc.projectField.text += this.firstChild.firstChild.firstChild.firstChild.attributes.projectName;
resourceSlot_mc.timeField.text += this.firstChild.firstChild.firstChild.firstChild.attributes.projectTime;
} else {
dateField.text += "Loading Error!";
}
}
databaseXML.load("resource.xml");
More Efficient Way?
Hey, I have this function but its abit on the long side, and I want to add some more variables to it, so it will be even longer. Is there a more efficient way of writing this? Thanks for any help, Harro.
code: sendLatest = new LoadVars();
getLatest = new LoadVars();
sendLatest.sendAndLoad("php/latest.php", getLatest, "POST");
getLatest.onLoad = function() {
_global.latestone = getLatest.latest1;
_global.latesttwo = getLatest.latest2;
_global.latestthree = getLatest.latest3;
_global.latestfour = getLatest.latest4;
_global.latestfive = getLatest.latest5;
_global.latestsix = getLatest.latest6;
_global.latestseven = getLatest.latest7;
_global.latesteight = getLatest.latest8;
_global.latestnine = getLatest.latest9;
_global.latestten = getLatest.latest10;
_global.latestidone = getLatest.latestid1;
_global.latestidtwo = getLatest.latestid2;
_global.latestidthree = getLatest.latestid3;
_global.latestidfour = getLatest.latestid4;
_global.latestidfive = getLatest.latestid5;
_global.latestidsix = getLatest.latestid6;
_global.latestidseven = getLatest.latestid7;
_global.latestideight = getLatest.latestid8;
_global.latestidnine = getLatest.latestid9;
_global.latestidten = getLatest.latestid10;
gotoAndStop(2);
};
[CS3] What Is Better/more Efficient Would You Say?
Just asking opinions here, what does everyone think is better for OOP and what is more effecient to do?
To have each class control itself with an onEnterFrame event inside the class? e.g.
Code:
class A extends MovieClip
{
public function A()
{
this.onEnterFrame = whatever;
}
}
class B extends MovieClip
{
public function B()
{
this.onEnterFrame = whatever;
}
}
Or to have a main class, instantiate the subclasses, and then run update methods in those instances through a for loop in the main class? e.g.
Code:
class A extends MovieClip
{
public function A()
{
}
public function update()
{
//do stuff
}
}
class B extends MovieClip
{
public function B()
{
}
public function update()
{
//do stuff
}
}
class Main extends MovieClip()
{
public function Main()
{
//instantiate instances of A and B, and add them to some arrays for looping through
this.onEnterFrame = this.enterFrameHandler;
}
private function enterFrameHandler()
{
//loop through arrays of instances and run update() in them
}
}
[F8]/[CS3]Which Is More Efficient?
I'm working on a website with a flash header (pretty big one) and the content in PHP (html). I have a section about in the middle (flash as well, but half the width of the above header) of the page which displays the current promotions (featured products).
I can include this part either as a piece of the upper header and use wmode opaque and show on top with z-index (on the left and right side) the html menus OR have them as 2 separate, independent swf files (and i'm not reffering here to a loadMovie in the bigger, upper header, just another embed).
My question is which solution is better, especially if taking into consideration resource consumption especially but also bandwidth, time to load and eventual problems which could arrise?
Is This Efficient?
Im making a space arcade shooter. Generaly i have my enemy ships, but instead of making a bunch im just duplicating them. So every time they duplicate they add themselves to an Array called books (don't ask, i went too far to change it to anything else... heh).
The lasers that the player ship shoots has a constantly running for loop that runs through the Array to see if the laser is colliding with any object in the array (any of the enemies).
HOWEVER! im shooting only one laser in a stream right now. Later on i want to include powerups to add diff types of lasers and more#'s of them and the such.
Question is: If i have so many shooting later, that will be a lot of for loops right? so won't that slow everythign down? I want to know before i go too far.
Efficient?
onClipEvent(enterFrame) {
//y for horizontal walls
if(_root.wall1.hitTest(_root.player)){
setProperty(_root.player, _y, vLastY);
} else if(_root.wall2.hitTest(_root.player)) {
setProperty(_root.player, _y, vLastY);
} else if(_root.wall3.hitTest(_root.player)) {
setProperty(_root.player, _y, vLastY);
} else if(_root.wall4.hitTest(_root.player)) {
setProperty(_root.player, _y, vLastY);
} else if(_root.wall5.hitTest(_root.player)) {
setProperty(_root.player, _y, vLastY);
} else if(_root.gate1.hitTest(_root.player)) {
setProperty(_root.player, _y, vLastY);
} else if(_root.gate2.hitTest(_root.player)) {
setProperty(_root.player, _y, vLastY);
} else if(_root.gate3.hitTest(_root.player)) {
setProperty(_root.player, _y, vLastY);
} else if(_root.key1.hitTest(_root.player)) {
_root.gate1.gotoAndPlay(2);
_root.key1.gotoAndPlay(2);
} else if(_root.key2.hitTest(_root.player)) {
_root.gate2.gotoAndPlay(2);
_root.key2.gotoAndPlay(2);
} else if(_root.key3.hitTest(_root.player)) {
_root.gate3.gotoAndPlay(2);
_root.key3.gotoAndPlay(2);
} else if(_root.endlevel.hitTest(_root.player)) {
_root.gotoAndPlay(2);
}
// x for vert walls
if(_root.wallA.hitTest(_root.player)) {
setProperty(_root.player, _x, vLastX);
} else if(_root.wallB.hitTest(_root.player)) {
setProperty(_root.player, _x, vLastX);
} else if(_root.wallC.hitTest(_root.player)) {
setProperty(_root.player, _x, vLastX);
} else if(_root.wallD.hitTest(_root.player)) {
setProperty(_root.player, _x, vLastX);
}
if(Key.isDown(38)) {
//38 is down arrow
vlastY = getProperty(_root.player, _y);
vLocationY = getProperty(_root.player, _y);
setProperty (_root.player, _y, vLocationY -10);
}
if(key.isDown(40)) {
//40 is up arrow)
vlastY = getProperty(_root.player, _y);
vLocationY = getProperty(_root.player, _y)
setProperty (_root.player, _y, vLocationY +10);
}
if(key.isDown(37)) {
//37 is left arrow
vLastX = getProperty(_root.player, _x);
vLocationX = getProperty(_root.player, _x)
setProperty (_root.player, _x, vLocationX -10);
}
if(key.isDown(39)) {
//39 is right arrow
vLastX = getProperty(_root.player, _x);
vLocationX = getProperty(_root.player, _x)
setProperty (_root.player, _x, vLocationX +10);
}
}
that is the code i am using for this maze type game i am trying to make, and everything works great, but what i'm wondering is, if thats how you have to do it? so if i have 60 maze walls, i'm going to have to write 1 if statement and 59 else statements?
Which Is More Efficient?
Which is the most efficient method of loading data in: LoadVars, or LoadVariables?
I need to do a data driven (ASP + Access) Flash site, and was wondering which is the most efficient to use (mainly in terms of speed for visitors).
Thanks in advance
Is There A More Efficient Way?
Guys i need help with the following effect,
let's say i have 4 circular icons...on rollover i'd like to zoom in on them, well one at a time, and at the same time i want the other icons to be pushed out of the way (so they're all visible no matter how big the zoomed in overstate is (or how far apart they are from each other for that matter).
RageW0lf helped me a little bit... basically keeping every one of them at a distance (ActionScript:
if (mysymbol._xscale>100) {
this._x = mysymbol._xscale - 100 + 15;
}
With 5 or so buttons this can get really bulky i mean each of the buttons needs to know if the rolledOver button is on the left or right in order to slide to the right (+x) or left (-x)
Do you guys know a more efficient object oriented way of doing this. Help if you do or have any idea how to go about it ,
Thanks in advance,
Artom
More Efficient
I plan on making a portfolio of images for my site. I want to have a small thumbnail and a larger version of th image. When you roll over the thumbnail the large one pops up.
I know how to do this but I want to keep my file size to a minimum. So for those technically inclined out there here are a few questions.
Will loading Jpegs from external files be "much" slower than haveing a full sized jpeg in my library?
If I Keep my jpegs in my movie library is it more efficient to have the thumbnails made up from the orginal image (just shrink them down) or should I load in separate jpeg thumbnails.
Thanks guys
Most Efficient Way To Use A Bmp As A Bg
hi,
i am looking for some advice please. i want to make a flash site that will have 3 or 4 sfw files. each swf has the same background image that takes up all the movie.
it doesn't seem right to load it each time i load a new swf on a different level but i can't see how you set the bg to be transparent. ideally i think i should have a swf with the bg image on it and then that loads the content swf on top. then i could load and unload swfs.
what am i missing??
cheers
Efficient?
onClipEvent(enterFrame) {
//y for horizontal walls
if(_root.wall1.hitTest(_root.player)){
setProperty(_root.player, _y, vLastY);
} else if(_root.wall2.hitTest(_root.player)) {
setProperty(_root.player, _y, vLastY);
} else if(_root.wall3.hitTest(_root.player)) {
setProperty(_root.player, _y, vLastY);
} else if(_root.wall4.hitTest(_root.player)) {
setProperty(_root.player, _y, vLastY);
} else if(_root.wall5.hitTest(_root.player)) {
setProperty(_root.player, _y, vLastY);
} else if(_root.gate1.hitTest(_root.player)) {
setProperty(_root.player, _y, vLastY);
} else if(_root.gate2.hitTest(_root.player)) {
setProperty(_root.player, _y, vLastY);
} else if(_root.gate3.hitTest(_root.player)) {
setProperty(_root.player, _y, vLastY);
} else if(_root.key1.hitTest(_root.player)) {
_root.gate1.gotoAndPlay(2);
_root.key1.gotoAndPlay(2);
} else if(_root.key2.hitTest(_root.player)) {
_root.gate2.gotoAndPlay(2);
_root.key2.gotoAndPlay(2);
} else if(_root.key3.hitTest(_root.player)) {
_root.gate3.gotoAndPlay(2);
_root.key3.gotoAndPlay(2);
} else if(_root.endlevel.hitTest(_root.player)) {
_root.gotoAndPlay(2);
}
// x for vert walls
if(_root.wallA.hitTest(_root.player)) {
setProperty(_root.player, _x, vLastX);
} else if(_root.wallB.hitTest(_root.player)) {
setProperty(_root.player, _x, vLastX);
} else if(_root.wallC.hitTest(_root.player)) {
setProperty(_root.player, _x, vLastX);
} else if(_root.wallD.hitTest(_root.player)) {
setProperty(_root.player, _x, vLastX);
}
if(Key.isDown(38)) {
//38 is down arrow
vlastY = getProperty(_root.player, _y);
vLocationY = getProperty(_root.player, _y);
setProperty (_root.player, _y, vLocationY -10);
}
if(key.isDown(40)) {
//40 is up arrow)
vlastY = getProperty(_root.player, _y);
vLocationY = getProperty(_root.player, _y)
setProperty (_root.player, _y, vLocationY +10);
}
if(key.isDown(37)) {
//37 is left arrow
vLastX = getProperty(_root.player, _x);
vLocationX = getProperty(_root.player, _x)
setProperty (_root.player, _x, vLocationX -10);
}
if(key.isDown(39)) {
//39 is right arrow
vLastX = getProperty(_root.player, _x);
vLocationX = getProperty(_root.player, _x)
setProperty (_root.player, _x, vLocationX +10);
}
}
that is the code i am using for this maze type game i am trying to make, and everything works great, but what i'm wondering is, if thats how you have to do it? so if i have 60 maze walls, i'm going to have to write 1 if statement and 59 else statements?
Is There A More Efficient Way?
Guys i need help with the following effect,
let's say i have 4 circular icons...on rollover i'd like to zoom in on them, well one at a time, and at the same time i want the other icons to be pushed out of the way (so they're all visible no matter how big the zoomed in overstate is (or how far apart they are from each other for that matter).
RageW0lf helped me a little bit... basically keeping every one of them at a distance (ActionScript:
if (mysymbol._xscale>100) {
this._x = mysymbol._xscale - 100 + 15;
}
With 5 or so buttons this can get really bulky i mean each of the buttons needs to know if the rolledOver button is on the left or right in order to slide to the right (+x) or left (-x)
Do you guys know a more efficient object oriented way of doing this. Help if you do or have any idea how to go about it ,
Thanks in advance,
Artom
Is There A More Efficient Way Than This...?
I have a movie with three navigation tabs. These tabs all have the same behaviours. The code I have written works perfectly well, but it just isn't very elegant. There must be a better way than the way I have done it.
Can anyone help me by showing me a more efficient way to code this? :-
CODE//-----------define all button actions-----------------
tab01.onRollOver = function() {
moveTab(tab01, moveSpeed);
};
tab01.onRollOut = function() {
returnTab(tab01, moveSpeed);
};
tab01.onPress = function() {
colourTab01.setTint(255, 0, 0, clickShade);
};
tab01.onRelease = function() {
colourTab01.setTint(0, 0, 0, 0);
gotoAndStop("tab01");
interaction(1);
};
tab02.onRollOver = function() {
moveTab(tab02, moveSpeed);
};
tab02.onRollOut = function() {
returnTab(tab02, moveSpeed);
};
tab02.onPress = function() {
colourTab02.setTint(255, 0, 0, clickShade);
};
tab02.onRelease = function() {
colourTab02.setTint(0, 0, 0, 0);
gotoAndStop("tab02");
interaction(2);
};
tab03.onRollOver = function() {
moveTab(tab03, moveSpeed);
};
tab03.onRollOut = function() {
returnTab(tab03, moveSpeed);
};
tab03.onPress = function() {
colourTab03.setTint(255, 0, 0, clickShade);
};
tab03.onRelease = function() {
colourTab03.setTint(0, 0, 0, 0);
gotoAndStop("tab03");
interaction(3);
};
//-----------------end button actions---------------------
More Efficient Way?
There has got to be a more effecient way of writing this:
ActionScript Code:
chart_btn._alpha = 0;
slider_btn._alpha = 0;
crosstab_btn._alpha = 0;
chart_btn.onRollOver = function() {
this._alpha=100;
}
chart_btn.onRollOut = function() {
this._alpha=0;
}
slider_btn.onRollOver = function() {
this._alpha=100;
}
slider_btn.onRollOut = function() {
this._alpha=0;
}
crosstab_btn.onRollOver = function() {
this._alpha=100;
}
crosstab_btn.onRollOut = function() {
this._alpha=0;
}
Sandman9
Which Is More Efficient?
I have an XML onLoad event that reads loads data into a data object. Is there any difference in efficiency between having the XML handler set the property directly or calling a method on the object that sets the property?
Which Syntax Is More Efficient?
Someone has told me that the slash syntax is much more efficient than dot syntax? And just the same that tellTarget runs faster than with.
Is it true?
How Can I Make This More Efficient?
Help! Check this out: http://simonabrams.com/drawing/paint_test.swf
I'm having a couple of problems with this movie. I need to do two things:
1) Add a "crayon" as a cursor, and make the circle that is the "brush" invisible
2) I need to make this so it doesn't slow down to a crawl after playing with it for a while.
Basically, I need to make it look like the user is picking up a crayon, and gets to color in the image (one crayon magically colors in all the colors of the image).
Any ideas? By the way, this thing is based on the "Draggable Magnifying Glass by The Freehand Site (available as an extension from Macromedia), and the "simple airbrush" I found somewhere within these boards. The .fla file is in http://simonabrams.com/drawing/
Thanks, guys.
- Simon
[Edited by flysi on 02-05-2002 at 07:46 PM]
A More Efficient Animation
I have several pict files and type in a movie I'm making. Will the movie player file run better if I break apart the picts and the text before exporting it or doesn't it matter. I seem to notice some speed issues and I'll break them apart if it will help.
Wondering What Would Be Efficient
Have several layers, one has an emblem, another has buttons, and another has visible paths for a "windy" effect that the buttons will follow. I must have the paths above the emblem layer. Then I would like the buttons on top of the paths layer, but I would like the buttons to appear to come from behind the emblem. Does anyone have suggestions? I was thinking that I could use AS to rearrange the layers but thought I might be making something fairly simple into a mess. I am fairly new to this so it would help if you talked to me like I am 5.
Thanks for any time, help and knowledge,
Va
More Efficient Coding
Hi guys,
I'm trying to learn to code a bit more efficient. But I am afraid need some help.
In the following code
a card is mc, consisting of a rectangle, with a textfield inside wich gets its text from an array, named card1, card2 etc.
15 targets ( 5 rows of 3) are on the stage, named T1a, T1b, T1c, T2a, T2b etc.
First one:
this is the code I use now:
* * *
// move card1
card1.onPress = function () {
this.startDrag();
};
card1.onRelease = function () {
this.stopDrag();
};
card1.onReleaseOutside = function () {
this.stopDrag();
};
// end
* * *
As I have 15 cards, I need to repeat this 15 times. Each card will hold text which it gets from an array. I have the cards on the stage at the beginning of the movie (yes my next thing is I will try to do a while loop with a duplicateMovie)
Second one, which gives me more headaches:
This code works fine, but will get very long if I have to do it for 15 cards and 15 targets (this is for three cards and three targets):
* * *
// snap card1 to target on Mouse up
card1.onMouseUp = function() {
// check if two card or on the same place, if so move it.
if (this.hitTest(card2)) {
card1._x = 50;
card1._y = 50;
}
if (this.hitTest(card3)) {
card1._x = 50;
card1._y = 50;
}
// check if this card hits a target, if so, snap
if (this.hitTest(T1a)) {
this._x = T1a._x;
this._y = T1a._y;
trace (card1._y);
} else if (this.hitTest(T1b)) {
card1._x = T1b._x;
card1._y = T1b._y;
trace (card1._y);
} else if (this.hitTest(T1c)) {
card1._x = T1c._x;
card1._y = T1c._y;
trace (card1._y);
}
};
// end
* * *
At the first bit I kept getting errors on this code:
if (this.hitTest(card2)) OR (this.hitTest(card3)) {
card1._x = 50;
card1._y = 50;
}
This especially gives me headaches. I encountered the same problem trying use something similar with && / AND.
Thanks a LOT,
Papermouse
Efficient Coding
I'm trying to find an efficient way to test what hit a MC...
I have an action in a MC on its frame to test for a hittest on 5 different objects...like this
Code:
if(_root.blah1.hitTest(this)||_root.blah2.hitTest(this)||_root.blah3.hitTest(this)||_root.blah4.hitTest(this)||_root.blah5.hitTest(this))
{
something something;
}
and now that i got other things working , i am coming back to this and trying to make it like this...
Code:
if(_root.blah1.hitTest(this))
{
blah1.gotoAndStop("Something");
}
but i dont wanna do an if for each blah MC... because then i have to do it again... so that would be 10 ifs... I was just wondering if anyone knew how to do this an easier way..Anyone?, i though maybe a switch statement... but i have no clue how that would work.... Please help...thanks,
Peace,
~Bill
Most Efficient Method
Hi. I am creating a tile-map based game in Flash sort of like Chip's Challenge. When you start the game, the first level loads and then you play that level. Then the second level loads and you play that level. Same with the third, fourth, etc. I am trying to make the shortest load times possible, since it will be played over the internet (by a lot of dial-up users). So what would be the best way to store my tiles for the levels? A lot of the same tiles will be used throughout various levels, but not every level needs ALL the tiles.
Each level is it's own SWF, so I COULD put only the tile images used in each level in it's SWF, but since some of those tiles are used in other levels, it seems kinda of a waste to have to duplicate them in a future level's SWF. I thought that I could put all the tiles in a shared library and then just pull the ones I needed in each level, but then I discovered that it will load ALL of that shared library and not JUST the symbols I need. I am trying to cut down on loading time as much as possible. Does anyone have any ideas what I could do?
Efficient Comparison
Is there a more efficient way to write this?
code:
m = 6;
if((m == 3) || (m == 6) || (m == 9)){
trace("it's in there");
} else { trace("sorry, it is not in there");}
Thanks.
If Else Dilemmas - More Efficient Way?
Currently I'm using an actionscript on a button, after the user has entered some data in the input text boxes.
There must be a more efficient way of doing it. Somebody mentioned the possibility of using an array, rather than six separate if...else statements, but I don't know how to do it.
Also, the (else) segment doesn't seem to be working properly. If the user doesn't enter a name, then it returns the box as blank, rather than with the (if) section of the statement.
Can anybody offer a suggestion or two? Most appreciated. Please note I have limited ActionScript knowledge, so as much detail as possible would be good.
on (release, keyPress"<Enter>") {
gotoAndStop(10);
if (Fairy=="") {
FairyMsg = "You did not choose a name for the fairy. The default name is Bella-Rose.";
} else {
FairyMsg = + Fairy + " for the fairy";
}
if (JB1=="") {
JB1Msg = "You did not choose a name for the first jitterbug. The default name is Jub-Jub.";
} else {
JB1Msg = + JB1 + " for the first jitterbug";
}
if (JB2=="") {
JB2Msg = "You did not choose a name for the second jitterbug. The default name is Dot.";
} else {
JB2Msg = + JB2 + " for the second jitterbug";
}
if (JB3=="") {
JB3Msg = "You did not choose a name for the third jitterbug. The default name is Lily.";
} else {
JB3Msg = + JB3 + " for the third jitterbug";
}
if (Kingfisher=="") {
KingfisherMsg = "You did not choose a name for the kingfisher. The default name is Jonathan."
} else {
KingfisherMsg = + Kingfisher + " for the kingfisher"
}
if (FairyPrince=="") {
FairyPrinceMsg = "You did not choose a name for the fairy prince. The default name is Frederic."
} else {
FairyPrinceMsg = "and " + FairyPrince + " for the fairy prince."
}
}
More Efficient Function
Can anyone help me make this code more elegant, or suggest another way of doing it?
It is a multiple response question, but the answers all need to be concatentaed into one big string before they are sent, they cannot be sent one at a time
aOn is set when the button for a particular response is clicked, 1=on, 0=off, sendAnswer is called whenever the button is clicked(either on or off)
Cheers.
sendAnswer = function() {
if (aOn==1){
aAns="this is answer a, "
}else{
aAns=" "
}
if (bOn==1){
bAns="this is answer b, "
}else{
bAns=" "
}
if (cOn==1){
cAns="this is answer c, "
}else{
cAns=" "
}if (dOn==1){
dAns="this is answer d, "
}else{
dAns=" "
}if (eOn==1){
eAns="this is answer e, "
}else{
eAns=" "
}if (fOn==1){
fAns="this is answer f, "
}else{
fAns=" "
}if (gOn==1){
gAns="this is answer g, "
}else{
gAns=" "
}if (hOn==1){
hAns="this is answer h. "
}else{
hAns=" "
}
answer = aAns + bAns + cAns + dAns+ eAns + fAns + gAns + hAns
trace(answer);
}
How Can I Make This More Efficient
Here is a menu which is part of a much larger fla.
How can I make the scripting more efficient? A good start would be to stop the MCs from calling when not moving, and top two menu items contain different code from my (failed) attempts at solving the problem.
I am using MX.
thanks to all
I Want To Make This More Efficient
Does anyone know a way to streamline this?
its area reset button for a whole bunch of MC (total of 70)
this is just a section.
so on release I want to send the MCs back to their origins. this does it, but its hell to code.
any effeciency advice?
==============================
_root.reset_btn.onRelease = function (){
_root.word0._x=26.1;
_root.word0._y=133.9;
_root.word1._x=26.1;
_root.word1._y=170.1;
_root.word2._x=26.1;
_root.word2._y=206.3;
_root.word3._x=26.1;
_root.word3._y=241.9;
_root.word4._x=26.1;
_root.word4._y=277.5;
_root.word5._x=26.1;
_root.word5._y=313.1;
_root.word6._x=26.1;
_root.word6._y=369.9;
_root.word7._x=26.1;
_root.word7._y=403.9;
_root.word8._x=26.1;
_root.word8._y=437.8;
Thanks in advance.
Mark
HitTest Efficient?
If I have a game where I want to detect if a bullet collides with an enemy(where there can be 20+ enemies on the screen), which is more efficient?
Method 1 : have an onEnterFrame which loops through each enemy and detects if the distance from the bullet to each enemy is less than a certain amount (which means a collision has occured)
or
Method 2 : put all the enemies inside a movie clip... then do a hitTest between the enemy movie clip and the bullet movie clip. If hitTest returns true, only then loop through each enemy and find out which enemy hit the bullet
Hope that maks sense,
Thanx!
Ryan
Efficient Coding
Hi guys, Is there a way to write this code more efficiently?
You have 10 objects on in a game, which disapear through the game with, box01.enabled =false; (there could be 15 pieces).
on reset, I set them all back to true. with
Code:
box01.enabled = ture;
box02.enabled = true;
///etc. to ///
box15.enabled = true;
There has to be some efficient way of doing this, like
Code:
box".".enabled = true;
/// to get them all without me typing them all out////
any ideals?
thanks.
How Would You Make This More Efficient?
how would u condense this code? it's a simple turn text brown when button is rolled over and turn back to white when roll out. I know this could be done easily from the button states by changing the color of the typed text there, but I am trying to learn AS3.
peace
Code:
// home text is text displayed on the Stage given a name.
// home_btn, blog_btn, bio_btn etc,,,buttons on the Stage.
// Get access to the ColorTransform instance associated with home text.
var homeButtonText:ColorTransform = home_mc.transform.colorTransform;
var blogButtonText:ColorTransform = blog_mc.transform.colorTransform;
var galleryButtonText:ColorTransform = gallery_mc.transform.colorTransform;
var contactButtonText:ColorTransform = contact_mc.transform.colorTransform;
var bioButtonText:ColorTransform = bio_mc.transform.colorTransform;
var pressButtonText:ColorTransform = press_mc.transform.colorTransform;
// This function is called when home_btn is rolled over.
// apply the change to the display object
// Set the color of the ColorTransform object.
function makeBrown(event:MouseEvent):void
{
homeButtonText.color = 0x330000;
home_mc.transform.colorTransform = homeButtonText;
}
function makeBlogButtonTextBrown(event:MouseEvent):void
{
blogButtonText.color = 0x330000;
blog_mc.transform.colorTransform = blogButtonText;
}
function makeGalleryButtonTextBrown(event:MouseEvent):void
{
galleryButtonText.color = 0x330000;
gallery_mc.transform.colorTransform = galleryButtonText;
}
function makeContactButtonTextBrown(event:MouseEvent):void
{
contactButtonText.color = 0x330000;
contact_mc.transform.colorTransform = contactButtonText;
}
function makeBioButtonTextBrown(event:MouseEvent):void
{
bioButtonText.color = 0x330000;
bio_mc.transform.colorTransform = bioButtonText;
}
function makePressButtonTextBrown(event:MouseEvent):void
{
pressButtonText.color = 0x330000;
press_mc.transform.colorTransform = pressButtonText;
}
home_btn.addEventListener(MouseEvent.ROLL_OVER, makeBrown);
blog_btn.addEventListener(MouseEvent.ROLL_OVER, makeBlogButtonTextBrown);
gallery_btn.addEventListener(MouseEvent.ROLL_OVER, makeGalleryButtonTextBrown);
contact_btn.addEventListener(MouseEvent.ROLL_OVER, makeContactButtonTextBrown);
bio_btn.addEventListener(MouseEvent.ROLL_OVER, makeBioButtonTextBrown);
press_btn.addEventListener(MouseEvent.ROLL_OVER, makePressButtonTextBrown);
function makeWhite(event:MouseEvent):void
{
homeButtonText.color = 0xFFFFFF;
home_mc.transform.colorTransform = homeButtonText;
}
function makeBlogButtonTextWhite(event:MouseEvent):void
{
blogButtonText.color = 0xFFFFFF;
blog_mc.transform.colorTransform = blogButtonText;
}
function makeGalleryButtonTextWhite(event:MouseEvent):void
{
galleryButtonText.color = 0xFFFFFF;
gallery_mc.transform.colorTransform = galleryButtonText;
}
function makeContactButtonTextWhite(event:MouseEvent):void
{
contactButtonText.color = 0xFFFFFF;
contact_mc.transform.colorTransform = contactButtonText;
}
function makeBioButtonTextWhite(event:MouseEvent):void
{
bioButtonText.color = 0xFFFFFF;
bio_mc.transform.colorTransform = bioButtonText;
}
function makePressButtonTextWhite(event:MouseEvent):void
{
pressButtonText.color = 0xFFFFFF;
press_mc.transform.colorTransform = pressButtonText;
}
home_btn.addEventListener(MouseEvent.ROLL_OUT, makeWhite);
blog_btn.addEventListener(MouseEvent.ROLL_OUT, makeBlogButtonTextWhite);
gallery_btn.addEventListener(MouseEvent.ROLL_OUT, makeGalleryButtonTextWhite);
contact_btn.addEventListener(MouseEvent.ROLL_OUT, makeContactButtonTextWhite);
bio_btn.addEventListener(MouseEvent.ROLL_OUT, makeBioButtonTextWhite);
press_btn.addEventListener(MouseEvent.ROLL_OUT, makePressButtonTextWhite);
The Most Efficient Way For Hit Testing
So, to give a history on my project - I decided create Lemmings in AS3 as a first project.
I've never done anything this grand, so this has been a great learning experience.
So far, I can create my lemmings, and they spit out on a Timer (one every few seconds), and then the lemmings are placed into a second timer that advances them on a much faster pace. When they move forward, they're also checking for hitTests as well.
The hit Testing is done by creating an invisible square that represents the general area and then using the bitmapData.hitTest method, I can check for the opaque areas of my level.
I was pretty excited to get all this working, but a thought occured to me - to have 30 characters all walking on screen and reacting to the level at their own rate seems pretty cpu intensive.
Is there an efficient way for flash to run 30 individual characters who all realistically react to the environment in their own way?
Efficient Code
Hi!, is there any other way (more efficient) to do this:
Let's say that maxSpaces is a number = 5000
and offset is a number = 1
Code:
while( (maxSpaces - offset ) > 0 )
{
maxSpaces--;
txtDatos.text += " ";
}
It's making my script slow and I would like to know if there is a faster way to add blank spaces to a string without a loop... for example:
var newString:String = " " * 10;
Obviously that doesn't work... :-)
Efficient Preloader
After carrying out several searches I have found several methods of preloading and entire SWF (static content), however each method varies rather largely.
Could someone point me at the most efficient/clearest way of coding an AS3 loader which would in AS2 terms be referencing to _root.getBytesLoaded...
ty
More Efficient Way For Buttons?
I'm not to sure what the term would be to search this under as I am sure this has been asked before. Is there a more efficient way to code this? Thanks for your help.
homeLink_mc.addEventListener(MouseEvent.ROLL_OVER, linkOver);
homeLink_mc.addEventListener(MouseEvent.ROLL_OUT, linkOut);
homeLink_mc.addEventListener(MouseEvent.CLICK, onClick);
homeLink_mc.buttonMode = true;
aboutLink_mc.addEventListener(MouseEvent.ROLL_OVER , linkOver);
aboutLink_mc.addEventListener(MouseEvent.ROLL_OUT, linkOut);
aboutLink_mc.addEventListener(MouseEvent.CLICK, onClick);
aboutLink_mc.buttonMode = true;
beneLink_mc.addEventListener(MouseEvent.ROLL_OVER, linkOver);
beneLink_mc.addEventListener(MouseEvent.ROLL_OUT, linkOut);
beneLink_mc.addEventListener(MouseEvent.CLICK, onClick);
beneLink_mc.buttonMode = true;
techLink_mc.addEventListener(MouseEvent.ROLL_OVER, linkOver);
techLink_mc.addEventListener(MouseEvent.ROLL_OUT, linkOut);
techLink_mc.addEventListener(MouseEvent.CLICK, onClick);
techLink_mc.buttonMode = true;
custLink_mc.addEventListener(MouseEvent.ROLL_OVER, linkOver);
custLink_mc.addEventListener(MouseEvent.ROLL_OUT, linkOut);
custLink_mc.addEventListener(MouseEvent.CLICK, onClick);
custLink_mc.buttonMode = true;
partLink_mc.addEventListener(MouseEvent.ROLL_OVER, linkOver);
partLink_mc.addEventListener(MouseEvent.ROLL_OUT, linkOut);
partLink_mc.addEventListener(MouseEvent.CLICK, onClick);
partLink_mc.buttonMode = true;
Most Efficient Animation
hi,
do any of you know what the most efficient way to animate is? i.e. timeline, event timer with timeline, event enter frame with timeline, something else?
More Efficient RollOvers
Okay, I've decided to devote my day to researching how to become a more efficient programmer. All my previous flash projects, I've always wrote the same RollOver functionality for EVERY instance of the same button. What a drag...
I know there's gotta be a simple AS2 version of AS3's eventListeners.
So instead of:
Code:
my_mc1.onRollOver = function { trace("do something"); }
my_mc2.onRollOver = function { trace("do something"); }
my_mc3.onRollOver = function { trace("do something"); }
my_mc4.onRollOver = function { trace("do something"); }
my_mc5.onRollOver = function { trace("do something"); }
There's gotta be a way to write the function once and reference it for each instance. I've always been too lazy to learn this as I'm not a programmer and I merely went with what worked, but I think it's time I started saving myself some development time.
I looked up event listeners for AS2, but they seem a bit odd to me.
Can I write a function that is passed the instance name as a variable and reference it with "this"?
If anyone can pitch it on this, I'll sleep soundly with a smile on my face knowing I learned something today to make my life a tad bit easier.
Note: I'm a frame-coder. You wouldn't have guessed, right?
More Efficient Hit Tests?
I know i raised this issue before, but i didn't get any response, and i still need help with it.
I've been trying to make a few game things where it checks to see if objects have run into each other (as one does in games). However, i seem to always have to have lots of code running each time it enters a frame, which after a few objects appear, make everything slow down and lag lots. If anyone has some tips, it would be much appreciated.
Most Efficient Way Of Preloading?
Hi everyone,
What would you say is the most efficient / best way of creating a preloader for a website that will have lots of flash files to load?
Currently I have created a preloader AS2.0 class, code below...
ActionScript Code:
/*
Subclass of the inbuilt MovieClip class (inherits all MovieClip class Methods and Properties).
*/
class Preloader extends MovieClip {
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Class properties.
// Define class properties (also called class attributes) >
// The path to the movieClip which the preloader is watching.
private var path_Movie_Clip:MovieClip;
// Value to store the total number of bytes to be loaded.
private var bytes_Total:Number;
// Value to store the current amount of bytes loaded.
private var bytes_Loaded:Number;
// Value to store the current percentage of bytes loaded.
private var bytes_Loaded_Percentage:Number;
// Internal movieClips and text fields.
private var bar_Inside_mc:MovieClip;
private var percentage_Loaded_txt:TextField;
// The x and y co-ordinates of the preloader.
private var position_X:Number;
private var position_Y:Number;
// Class properties.
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Class constructor.
// Remember - function must have same name as the Class to be its constructor.
function Preloader () {
_x = position_X;
_y = position_Y;
bytes_Total = path_Movie_Clip.getBytesTotal();
bytes_Loaded = 0;
bytes_Loaded_Percentage = 0;
}
// Class constructor.
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Methods.
private function onEnterFrame ():Void {
// Get the current number of bytes loaded.
bytes_Loaded = path_Movie_Clip.getBytesLoaded();
// Work out the percentage of bytes loaded.
bytes_Loaded_Percentage = int ((bytes_Loaded/bytes_Total) * 100);
// Display the percentage.
update_Field_Percentage_Loaded_txt ();
// Rezise the bar.
update_Bar_Inside_mc ();
if (bytes_Loaded_Percentage >= 100) {
path_Movie_Clip.play ();
removeMovieClip (this);
}
}
private function update_Field_Percentage_Loaded_txt ():Void {
percentage_Loaded_txt.text = String (bytes_Loaded_Percentage);
}
private function update_Bar_Inside_mc ():Void {
bar_Inside_mc._xscale = bytes_Loaded_Percentage;
}
// Methods.
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
}
...which controls a movie clip called "Preloader" which I have to include in all my flash .fla files for it to work...I then start the preload by doing this...
ActionScript Code:
// Create new Preloader object.
var preloader_mc:Preloader;
preloader_mc = attachMovie("Preloader", "preloader_mc", 1, {path_Movie_Clip:_root, position_X:300, position_Y:100});
...is there are better more efficient way?
Thanks for you help.
More Efficient Code ...
There must be a more efficient way of writing this code:
Code:
if (i == 0) {
_root.topicTitle0 = thisLesson.title;
} else if (i == 1) {
_root.topicTitle1 = thisLesson.title;
} else if (i == 2) {
_root.topicTitle2 = thisLesson.title;
} else if (i == 3) {
_root.topicTitle3 = thisLesson.title;
} else if (i == 4) {
_root.topicTitle4 = thisLesson.title;
} else if (i == 5) {
_root.topicTitle5 = thisLesson.title;
}
NOTE: the variable of thisLesson.title changes elsewhere in the code at large so all I need is a way to write something like the following (which doesn't work by the way):
Code:
_root.topicTitle[i] = thisLesson.title
Thanks,
Stephen.
More Efficient Loading?
Im trying to set up a loading system that could be more effiicient. What im after:
1. the menu should load real fast. Then the user can browse it while the next levels are being loaded. (and by levels i mean levels of a game, like level 1..etc).
2. If the user was to start a new game, he would see a loading screen for level1.
3. while playing level 1, level 2 would be loading. And so on like that.
I think this could be real efficient if done right. I read in a similar post that this was not possible but i'd like a second (or few more) oopinions/suggestions.
The Most Efficient Component To Use
What would be the most efficient component to use for a one line piece of dynamic text?
A Lable; TextInput or TextArea component?
I would like to use the most suitable component for one line of dynamic text.
Also the esiest component to style as I would like 3 sizes of text and to be able to change the backgrounds.
I also tried using the custom declaration and not sure if this would be suitable or overkill:
import mx.styles.CSSStyleDeclaration;
var new_style:Object = new CSSStyleDeclaration();
_global.styles.myLableStyle = new_style;
new_style.setStyle("fontSize", 18);
myText1.setStyle("styleName", "myLableStyle");
When I use the setStyle it seems to work fine for my dynamic TextInput.
Any info on these components would really be helpfull.
Please see code is attached as a reference to what i want to do.
Thank you.
W Bell.
Attach Code
myText1.setStyle("borderStyle","none");
myText1.setStyle("backgroundColor", 0xCCCCCC);
myText1.setStyle("fontSize",10);
myText1.setStyle("fontWeight","bold");
myText1.setStyle("color",0x3C5375);
myText2.setStyle("borderStyle","none");
myText2.setStyle("backgroundColor", 0xFFFFFF);
myText2.setStyle("fontSize",12);
myText2.setStyle("fontWeight","normal");
myText2.setStyle("color",0x3C5375);
myText3.setStyle("borderStyle","none");
myText3.setStyle("backgroundColor", 0x3C5375);
myText3.setStyle("fontSize",14);
myText3.setStyle("fontWeight","normal");
myText3.setStyle("color",0x3C5375);
Edited: 01/21/2009 at 10:49:50 AM by W_Bell
Tips To More Efficient AS
Can anybody give me any tips on reducing the amount of resource needed to run the script??
is there an alternative to 'enterframe' :-??
thanks..
More Efficient Mp3 Streaming?
Alright, I've googled and perused the forum to no avail. :-)
I was wondering if there might be a better way to "stream" an mp3 as background music for a flash site. I know that this practice is generally frowned upon,and that many simply resort to using short musical loops, but I'm curious to see if there is a better method than the standard one that I'm currently using:
sndTunage.loadSound(songFolder + songTitle + ".mp3", true);
As one might expect, there's a significant slowing of the background animations as the mp3 loads. Unfortunately, I'm still using as 2.0 throughout this current project, so while as 3.0 may offer some newfound possibilities, I'm unable to implement them at this time.
Any suggestions or aid in this matter would be greatly appreciated. Thank you for reading, and have a wonderfully productive afternoon. :-)
More Efficient Code
Hi, I'm wondering if there is a more efficient to program buttons (either buttons or movie clips as buttons)?
The only way I know how to do this is to write an event listener for each state of the button, then write a function for each state. So for each button I may have three event listeners and three functions, which is six code entities for each button. Seems like there must be a better way.
Any coaching will be appreciated.
Code example below (doesn't include the functions):
mvDeveloper.addEventListener(MouseEvent.MOUSE_OVER , dimm1);
mvEducational.addEventListener(MouseEvent.MOUSE_OV ER, dimm2);
mvResume.addEventListener(MouseEvent.MOUSE_OVER, dimm3);
mvMusic.addEventListener(MouseEvent.MOUSE_OVER, dimm4);
mvSamples.addEventListener(MouseEvent.MOUSE_OVER, dimm5);
mvDeveloper.addEventListener(MouseEvent.MOUSE_OUT, bright1);
mvEducational.addEventListener(MouseEvent.MOUSE_OU T, bright2);
mvResume.addEventListener(MouseEvent.MOUSE_OUT, bright3);
mvMusic.addEventListener(MouseEvent.MOUSE_OUT, bright4);
mvSamples.addEventListener(MouseEvent.MOUSE_OUT, bright5);
mvDeveloper.addEventListener(MouseEvent.CLICK, slide1);
mvEducational.addEventListener(MouseEvent.CLICK, slide2);
mvResume.addEventListener(MouseEvent.CLICK, slide3);
mvMusic.addEventListener(MouseEvent.CLICK, slide4);
btnContact.addEventListener(MouseEvent.CLICK, contactMe)
mvSamples.addEventListener(MouseEvent.CLICK, samples);
btnSoundOff.addEventListener(MouseEvent.CLICK, soundOff);
Thanks, Doug
More Efficient Syntax
What's a nice short way to write this?
Code:
var line_1:Line_1;
var line_2:Line_2;
var line_3:Line_3;
var line_4:Line_4;
line_1 = new Line_1;// add from Library
line_1.name = "line_1";
line_1.x = 111;
line_1.y = 151;
addChild(line_1);
line_2 = new Line_2;// add from Library
line_2.name = "line_2";
line_2.x = 111;
line_2.y = 175;
addChild(line_2);
line_3 = new Line_3;// add from Library
line_3.name = "line_3";
line_3.x = 111;
line_3.y = 198;
addChild(line_3);
line_4 = new Line_4;// add from Library
line_4.name = "line_4";
line_4.x = 111;
line_4.y = 220;
addChild(line_4);
Efficient Code
Hello all,
I'm posting a new this because I can't quite find a similar solution from a previous thread. So if you know of one off the top of your head, plaese pass it along. But I'm looking to make my code more efficient, without the use of any onEnterFrame or any infinite prevFrame()... play() loops. I want these functions to be initialized. So here's what I have:
ActionScript Code:
b0.onRollOver = function(){
menu_over(0);
}
b0.onRollOut = function(){
menu_out(0);
}
b0.onPress = function(){
menu_select(0);
move0();
}
b1.onRollOver = function(){
menu_over(1);
}
b1.onRollOut = function(){
menu_out(1);
}
b1.onPress = function(){
menu_select(1);
move1();
}
(all the way down to...)
b8.onRollOver = function(){
menu_over(8);
}
b8.onRollOut = function(){
menu_out(8);
}
b8.onPress = function(){
menu_select(8);
move8();
}
I have 9 menu buttons and I'm coding the same thing over and over, but just switching the respective button number and variable number, I'd like to code it more efficiently. What I've tried was:
ActionScript Code:
for(i = 0; i <= 8; i++){
this["b"+i].onRollOver = function(){
menu_over(i);
}
this["b"+i].onRollOut = function(){
menu_out(i);
}
this["b"+i].onPress = function(){
menu_select(i);
eval("move"+i)();
}
}
... however, this was an unsuccessful attempt. Is there a more efficient way so I can end my insanity?
Thanks a bunch!
More Efficient 'if' Code ...
There must be a more efficient way of writing this code:
Code:
if (i == 0) {
_root.topicTitle0 = thisLesson.title;
} else if (i == 1) {
_root.topicTitle1 = thisLesson.title;
} else if (i == 2) {
_root.topicTitle2 = thisLesson.title;
} else if (i == 3) {
_root.topicTitle3 = thisLesson.title;
} else if (i == 4) {
_root.topicTitle4 = thisLesson.title;
} else if (i == 5) {
_root.topicTitle5 = thisLesson.title;
}
NOTE: the variable of thisLesson.title changes elsewhere in the code at large so all I need is a way to write something like the following (which doesn't work by the way):
Code:
_root.topicTitle[i] = thisLesson.title
Thanks,
Stephen.
|