ActionScript 2.0 :: [FMX]Substract Part Of Instance Name In Function?
Aug 1, 2004I have the following code from a tutorial on Kirupa:
Code:
_root.currMovie = "home";
container.loadMovie(_root.currMovie+".swf");
[code]....
I have the following code from a tutorial on Kirupa:
Code:
_root.currMovie = "home";
container.loadMovie(_root.currMovie+".swf");
[code]....
I have the following code from a tutorial on Kirupa:
Code:
_root.currMovie = "home";
container.loadMovie(_root.currMovie+".swf");
_root.home.gotoAndStop(2)
[Code]....
As you can see are the button names: home, about, service and contact. This are also the names of the external swf's. But now I have chanced my button names in: btn_home, btn_about, etc. Now is it a little stange to name my external swf's btn_home etc, so how can I substract the prefix btn_ from the buttons so that the externa swf's can keep their normal names? I know it has something to do with substr but I don't know how and where to implement it.
I'm new to AS3 and was wondering how I can use something like:
var mc:MovieClip = MovieClip(e.currentTarget);
As part of another instance name.
For example if the currentTarget was a move clip with an instance name of "oneNav" and then I wanted to control a movieclip with the name of "SuboneNav", how could I do it? All the variations of concatenation I'm familiar with weren't working. I even tied getting e.currentTarget.name instead but there always seems to be an issue.
I have 36 buttons on my stage that are named [thumbBut0, thumbBut1, thumbBut2,..., thumbBut35]. Each button is a thumbnail image. I want to have it so that when the user clicks on a given thumbnail, the full-sized image corresponding to the thumbnail gets loaded and viewed...yada, yada, yada... So, if the user clicks on thumbBut25, the 25th image gets viewed...
My question: is there some cool way that I could avoid writing 36 different (although they would be similar) "_level0.thumbButXX.onRelease = function()..." type things for each of the 36 buttons. In other words, when the user clicks the instance "thumbBut25" something grabs the "25" part out of the instance name, converts it to an integer, and passes it on to a function that loads up the image that corresponds to "25"?
I have a question how i add or substract 1 value to variable? up button should add 1 to display_week. down button should substract 1 from display_week.
HTML Code:
display_week = 0;
week(display_week,20);
week(display_week+1,100);
week(display_week+2,180);
_root.up.onRelease = function(){display_week++}
It does not work
How to substract .1 alpha from a hex color? For example:
[Code]....
I am writing a maze program for school. I am using a 2d array to represent to location of walls for the maze. The background (for figuring out where a player can move) is not the problem.I am using this algorithm for places the images...
for (i = 0; i < 22; i++) {for (j = 0; j < 16; j++) {if (maze[i][j] == 1) {instanceName = "wall" add i add j; //for multiple names for each instance
duplicateMovieClip("wall", newname = "instanceName", 1);
setProperty("instanceName", _x, (25*i+13));
[code]....
What needs to be done to use many copies of one instance to build the visible part of my maze? I want to be able to have all pieces anmed "wall" instead of "wall1", "wall2", etc...which isn't working anyway.
I have a general / somewhat newbie question. Is it better practice to call a function from another class like so:
[Code]...
Does one way free up more memory or enhance performance?
will not work if i invoke like this on button with this function:
function showMC(clip){
_root.content.drive.local.section5.clip.fade(6)
}
on (release) {
[Code]...
I have a situation where, upon loading my swf, I add an event listener to the stage to listen for keyboard commands. One of them is to listen for the spacebar, and if it is pressed, it should play a movie. The problem is, that movie is not loaded until later on, depending other user interactions, therefore, until it is loaded, the reference to it would be undefined.
But if I wait and add the listener for key commands only when the movie is loaded, then I can't utilize the listener for other keyboard commands, like RIGHT or LEFT, which are the buttons which get you to the movie in the first place. Is there a way to add a conditional or something to prevent that code from being executed if the video is not defined yet? Here's my code:
[code]...
Does creating a new instance of an Object that uses an identical name to an older instance, delete the previous instance? Or should the original instance be deleted first? The code uses a ridiculous amount of XML vars. Isn't it less memory intensive to parse the XML and save the properties to an Object, and then delete the XML Object, rather than keep the XML Object around and reference it's child nodes directly? Is it better form to break up a huge XML file (>600lines/3200vars) into smaller chunks?
View 1 RepliesI have 4 instances of the same button on a single layer in a timeline of the mc 'coverflow_mc' named 'ThatsMe_btn_a' to 'ThatsMe_btn_d' ie same button, same position.. it just changes instance name on 4 keyframes. Why does it call the function fine for button a but not for b,c, or d? There is a stop on each of these frames and I can see from the swf that it is stopping at the correct frames.
function thatsMe() {
right = new Sound();
right.attachSound("right");
[Code]....
So this is my code:
ActionScript Code:
onClipEvent(enterFrame) {
if (!this.already) {
setTimeout(win, 2000);
[Code]....
The problem is that I can't do trace(this); How to get it work? I have tried to do this.setTimeout etc..
I've got this function, in which I declare a variable. according to that variable I want to adress an instancename...
[Code]...
I'm using two functions, one for an onRollOver event and the other onRollOut.
The problem is that when the second mc calls either of the functions, the inital function running ends its cycle, leaving that animation unfinished.
Ok perhaps ive bitten off too much here...I know you are not supposed to parse xml/html to regex but the thing is there just arent many other options.Im using AS3.im parsing the source of textflowlayout text to a different format.
string to parse :
< fontFamily=Verdana encoding=unicode fontWeight="bold"> some text < fontFamily=Verdana encoding=unicode > some text < fontFamily=Arial encoding=unicode fontStyle="italic"> some text < fontFamily=Arial encoding=unicode fontWeight="bold" fontStyle="italic"> some text
what i really need is:
< fontname=Verdanabold encoding=unicode> some text < fontname=Verdana encoding=unicode > some text < fontname=Arialitalic encoding=unicode > some text < fontname=Arialbolditalic encoding=unicode > some text
logically i think of it as taking apart the string into substrings
checking if there are fontWeight or fontStyle in the substring
if there is then appending the font name with the weight or style so so that the font name becomes font NameWeightStyle.then rebuilding the string.The font could be any font with variouse styles or weights..so far:
pattern = /<(.*?)>/gixsm;
var matches:Object = pattern.exec(str);
var finalstring:String = "";[code]...........
I'am looking for a flv/video player which allow to seek for not loaded part of the video,just like on youtube.
View 1 RepliesWell I want to set up a function that will calculate the x position of where my MovieClip's instance name will go. Here is the code i currently have.
function xBtnPosition(btnName: String, btnXpercentage: Number):String
{
var xFinalPosition: String = -(((btnName.width * btnXpercentage) / btnName.scaleY));
[code].....
Got 9 MCs which I want a rollover effect for. I made 1, copied it and it's instance name 9 times. And made this script:
Code:
function menu_btn_over() {
myTween = new mx.transitions.Tween(_root.main.menu.btn.btn_parent, "_x", mx.transitions.easing.Strong.easeOut, _root.main.menu.btn.btn_parent._x, 0, inspeed);
[code]...
But it only works for one of the buttons. The one I made the copies from.I figured you could do this since it's the same MC? I could be wrong though. If that is the case, is there some way I can make the same action for every button without having to make a bunch of calls for each one? for example:
"_root.main.menu.btn1 <and> btn2 <and> btn3 <and> etc.onRollOut = function() {"
I have created a function that creates a pop-up text box: I have named instanceName as a String but sadly it doesn't work. The only way I can get it to work is to name the instance within the function. Is there any way of creating a variable for the instance name? [code]...
View 3 Repliesthe idea is that the site keeps tracks of whatever page is current and passes this variable to the alpha function which will target that movie instance to fade when moving to another page - then that page's name will be assigned to current.this is the code that i have now..
#include "alpha.as"
evolution.onRelease = function() {
this[current].gotoAndPlay(2);
[code].....
k the idea is that this movie keeps tracks of whatever page it's on using the variable current. when the button evolution is clicked it should jump to frame 2 of the movie whose instance name is contained in the variable current and also pass this variable to a function called alpha which fade that movie's instance when moving to another page - then that page's name will be assigned to current.
this is the code that i have now..
#include "alpha.as"
evolution.onRelease = function() {
this[current].gotoAndPlay(2);
this[current].alpha(5, 0);
};
all these buttons and movie instances are contained in the same movie clip and the variable current is declared in it too.
Got 9 MCs which I want a rollover effect for. I made 1, copied it and it's instance name 9 times. And made this script:
[Code]...
But it only works for one of the buttons. The one I made the copies from. I figured you could do this since it's the same MC? I could be wrong though. If that is the case, is there some way I can make the same action for every button without having to make a bunch of calls for each one? for example:
[Code]...
When I try to use this code to call a function for every instance of a certain class I get an error saying that there is a "call to a possibly undefined method removeInstance through a reference with static type flash.displayObject".
Code:
for (var i:int=0; i<=numInstances; i++) {
if (numInstances!=0&&getChildByName("b"+i)!=null) {
getChildByName("b"+i).removeInstance();
}
}
I am trying to add a simple navigation to an instance of a button on my stage through AS3. my code is below... I have used the same code in AS2, but i must be leaving something out in AS3..
btn_arrow_TL.onRelease = function() { gotoAndPlay("flyout_default"); }
Compiler Errors: 1120: Access of undefined property click.
I have a set of thumbnails in a "gallery" class calling a "feature" class that's presents/displays the associated content.
I'm stuck with a runtime problem where I have a thumbnail button calling a "feature" class. This "feature" class contains a function with an instance of a button listener. So everytime I call this function it creates a duplicate instance of this listener. - BAD
I would like to move this addListener instance out of the function in the "feature" class so it doens't multiply instances every time it's called by the thumbnail.
However, when I take the listener instance and it's function included out of the function in the "feature" class being called it can't access other functions in the "feature" class.
Is there a simple way around this so I can have button listeners in a class but not added every time the containing class is being called? Should I have these buttons in a separate class that just extends from the "feature" class?
I'm trying to define this function so I can pass the CardButtons sprite to the Add Cards function. It "works" but there's one problem: the CardButtons sprite used in the function is determined by the value of i at the time of the function call (or in other words, the value of i when I click the sprite).
I want the sprite passed to be literally the value of CardButtons[i] at the point when the function was defined.
CardButtons[i].addEventListener(MouseEvent.CLICK, CardFunctions[i]= function(){ AddCards(CardButtons[i],PlayerHand[player-1][PlayerHand[player-1].len gth-1]);});
Is there a way I can do this, or is there a better way to do what I'm trying to do?
I guess for further example:
I want CardFunction[0] to store the AddCards function with the value of CardButtons[0] passed, it should NOT be dependent on the value of i.
I'm getting into actionscript3 and was wondering if there was a way to make an 'onclick' type function that returns an id or an instance name. For example in jQuery you can do the following, which is great for then passing the id into an array or whatever you choose.
$('.menuButton').click(function(){
var collectedID = $(this).attr('id');
Is there an equivalent to this in AS3? I'm assuming grabbing the instance name would be the goal? I haven't run across ids in Flash yet.
I'm so getting confused with this,So i'm making a card game, and i'm just on the beginning of it. I've already added the objects on the stage and stored them on an array.now i made a function that when it executes the .x and .y properties of these cards would change. this is what i did, but nothing seems to happen.the array MyCards contain movieclip objects not strings and also, the function executes when an instance in the movieclip is clicked
ActionScript Code:
distCards(MyCards);
function distCards(cards:Array):void {
for (var i:int=0;i<cards.length ;i++) {
[Code]...
How can I get the instance of the class to call the dispatchEvent for the postTrace function.
1180: Call to a possibly undefined method dispatchEvent.
Code:
package {
import flash.display.*;
import flash.events.*;
[Code].....