ActionScript 2.0 :: Adressing Instance Name From Out Of Function?
Jun 4, 2003I've got this function, in which I declare a variable. according to that variable I want to adress an instancename...
[Code]...
I've got this function, in which I declare a variable. according to that variable I want to adress an instancename...
[Code]...
Is it possible to iterate through MV copies with the same instance name? It would be very useful for my project.
View 5 RepliesIm a bit confused about the adressing of .swf-files loaded into levels of another .swf-file.The adressing seem to be absolute, ie. if a sub.swf (which is loaded into a super.swf from another location) uses some sort of adressing (for instance, loading an image), that adress must include the path from the super.swf.
Cant you change that somehow, so that sub.swf's can adress other stuff relatively to its own adress?
Can you do that globally (so that relative adressing is used by every .swf)?Can you set it individually, so that adressing is relative only from the specified swf's?
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?
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'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.
Well 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 RepliesI 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.
the 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 have the following code from a tutorial on Kirupa:
Code:
_root.currMovie = "home";
container.loadMovie(_root.currMovie+".swf");
[code]....
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].....
Basically looking for a way to get the instance created when I use this function I've made, it seems to me "libItem" will be a new instance and I would like to re-assign that back to the item passed into the function so I can access the instance later.
Here is the function I created to create library on the stage...
Code:
function objectPlacer( libItem, instance:Class ):void {
libItem = new instance( );
addChild( libItem );
}
So here is how I call the function
Code:
// Function( var name, library item class name, pos x, pos y )
objectPlacer( i_ranks, txt_Ranking );
My problem is, I try to access "i_ranks" later with the following code...
Code:
i_ranks.x = 100;
And I get the error:
TypeError: Error #1010: A term is undefined and has no properties.
"i_ranks" is defined as a class member.
Also, if you know - what should types should I be assigning the parameters instance and libItem in the function?
I made this function,that is supposed to create a bunch of slides based on a parameter. That parameter should be the instance name:
Code:
function createSlide(instName:Object){
trace(instName);
this.createEmptyMovieClip(instName, this.getNextHighestDepth());[code]....
In the script I call the function with
Code:
createSlide("mySlide");
After execution, this error message appears: Error: A 'with' action failed because the specified object did not exist.The trace statement returns the instance name -"mySlide"- When I replace instName with a stringtype name like "mySlide", it works fine.But I don't want that 'cause in that case I have to write a specific function for each slide.
I create a new MovieClip, call it Somehow, and link it to the name "MyClip", for example.[code]...
They must be MovieClips, because the functions not only response with hello, like in the example.
So I want to create the Clip copies and call the functions in one step. This example is also not working when i put it inside of a onLoad, or onEnterFrame and so on.
How can I access instance variables in closure(inner function) for this style: this['varName']?
[Code]...
Is there a way to have a function draw a box around an object by finding the objects instance name via a string?
such as:
Code:
function BoxObject(object) {
//code to draw a box around the object
}
and then juts have an object with an instance name, like "my_mc" and then call the function on a keyframe like:
BoxObject("my_mc");
I have a singleton class that looks something roughly like this (only with more bindable public properties):
public class Session extends EventDispatcher
{
private var _Id:String;
private static const _instance:Session = new Session( SingletonLock );
private static const SESSID_CHANGED:String = 'SessionIdChanged';
[Code]...
The abnormal behavior I'm discovering is that the event listeners registered through registerOnSessionChange are indeed being called when the session Id changes, but the MXML data binding expression is not updating. I've tried all combinations of dispatching the event during the capture phase, and making it not cancelable, but to no avail. My understanding of [Bindable (event= ...)] is that the MXML should update the url string when the event specified is dispatched, so what am I doing wrong or misunderstanding?
Note: I realize there are lots of different ways of doing the singleton pattern in Actionscript, but unless the way I am doing it is actually causing my problem somehow,