Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash








Referencing Objects By Name Created At Runtime


Referencing objects by name created at runtime, how do you do it?
Ive remember reading that its tough, but can't seem to find the work around.
I have thumbnail objects (with a thumb class) that are created in a loop and added to a thumbholder class, with the name property added (thumb.name, which when traced is thumb0, thumb1, etc). After runtime I want to interact with the thumbs via mouse events in the thumbholder, e.g. when thumb0 is clicked thumb4 is moved to x=60. But trying to reference thumb0 doesnt work and when I reference thumb it will always return the final thumb, e.g. thumb5.




KirupaForum > Flash > ActionScript 3.0
Posted on: 03-27-2008, 09:36 AM


View Complete Forum Thread with Replies

Sponsored Links:

Referencing Objects Created By Functions
Hi, I've been using Actionscript 2 for a while, bit of a newbie with 3 (and objects and classes etc.) though, so I'm just running into small issues from time to time I'm completely confused by. :|

So I have a function, called initMainMenu that includes all the code for creating a menu, which is a list of movie clips inside a container movie clip.
Inside that function I create a movie clip object called mainMenuContainer, and an array called menuList.

Then I create movieclip objects using items in the library, and add them to the menuList array. These are the items in the menu. Then I call a second function from inside this function, called arrangeMenu, which just does a little for in loop to give the menu items a y property, adds EventListeners to them, and adds them as children of the mainMenuContainer. Maybe that's a clumsy way of doing things, but that's not the problem.
The problem is that Flash won't run the second function because when it gets to the part where I say

mainMenuContainer.addChild(array[ i]) - space added to avoid italics tag :P

it says:

"1120: Access of undefined property mainMenuContainer."

So I'm thinking, "Okay, what the hell?"
It wasn't necessary to keep that as a separate function, so I solved this by just putting the contents of the arrangeMenu function inside initMainMenu. But that's a temporary solution to a broader problem, because now I've got the same problem with a third function (the function called by the EventListeners) that I can't just lump inside the first. How come I can't refer to objects created by a function from inside other functions? Is it a problem with the order I'm writing them in, or how they're called? I am confused. :|

View Replies !    View Related
Referencing Objects Created With A Loop
I know there is simple answer here but Im getting tired so here I am.

I am creating buttons for a menu dynamically based on the amount of items in an array. I can create the buttons and labels for them and even make them access their corresponding page that they link to. My question is for the rollover effect, when I roll over I want the text on the button to shift to the right, but because all the buttons were added in a loop I can only reference the last button created.
I think my question is how do I change the instance name of an object? I though .name did it but that doesn't seem to change the actual reference name of an object.

here is what I have:


Code:
for(i=0; i <= numPages - 1; i++){
var menubut:MovieClip = new menuBut();
menubut.name = "b"+(i + 1);
menubut.y = 10 + i * 20;
menubut.pageTitle.text = pages[i];
menubut.addEventListener(MouseEvent.CLICK, changePage);
menubut.addEventListener(MouseEvent.MOUSE_OVER, overMenu);
menubut.addEventListener(MouseEvent.MOUSE_OUT, offMenu);
menucon.addChild(menubut);
}

function overMenu(event:MouseEvent):void{
temp = event.target.name;
menucon[temp].pageTitle.x += 3;
}

function offMenu(event:MouseEvent):void{
temp = event.target.name;
menucon[temp].pageTitle.x -= 3;
}
pages is the array and numPages is the length of that array. menucon is the mc that all the menu buttons go into.

View Replies !    View Related
Tweening MC's Created At Runtime
ok screw the search tool, I don't have all frickin day.

I'm using the drawing API to create a square at %0 alpha.

The problem is, if I set the alpha as a beginFill param, the tween to %100 alpha does not work.
If, immediatly preceeding the tween command I manually set the alpha to 0, it works.
Does anyone know why this is?

DOES NOT WORK
code:
this.createEmptyMovieClip("myClip", this.getNextHighestDepth());
myClip.beginFill(0xFFFFFF, 0);
myClip.moveTo(...)
myClip.lineTo(...)
myClip.endFill();
myClip.tween(100, 1);


WORKS
code:
this.createEmptyMovieClip("myClip", this.getNextHighestDepth());
myClip.beginFill(0xFFFFFF);
myClip.moveTo(...)
myClip.lineTo(...)
myClip.endFill();
myClip._alpha = 0;
myClip.tween(100, 1);

View Replies !    View Related
Add Variable To Runtime Created Mcs? How?
Hi, i am creating multiple movie clips on stage using the following code which works great. However, you will notice that i add a MOUSE_DOWN listener, so the movie clips have a function that gets called every time you click on one of them.


Code:
for (var i=0; i < myXML.slide.length(); i++) {
var _Class2:Object = getDefinitionByName("whitebox") as Class;
var square:MovieClip = new _Class2();
square.name = "whitebox"+i;
square.x = 16*i;
square.y = 0;
square.addEventListener(MouseEvent.MOUSE_DOWN, whiteBoxDown);
square.buttonMode = true;
square.mouseChildren = false;
var target = contentMC.innerMC.getChildByName("squares1");
target.addChild(square);
}
my problem is that the whiteBoxDown function needs to use a variable, which is different for each movie clip. Lets say its a tween. The first movie clip needs to go to 0*500, the second at 1*500 and so on. How can i create a variable in each movie clip so i can use it in my function like that:


Code:
this.x = myVar*500;
i tried using square.myVar = 1 for example (right after creating the movie clip) but it comes up as undefined. This worked fine in as2 and i dont have a clue how to solve it in as3. any help?

View Replies !    View Related
Preload MC Created At Runtime
Hi,

I am working on a site and I am new to AS3, but I am starting to get a grip of it. I have a class Page.as. This class creates a background and loads xml from a drupal module and loads the xml data into textfields and so on. This works great and uses no external assets, all is created on the fly.

I initiate a page by doing so..


Code:
var frontpage:Page = new Page("home");
this.addChild(frontpage)
The thing I want to do is make a preloader for the page loading, cause everytime i load a new page there is some loading time because of the xml loading and loading of pictures inside and so on..

How can I listen to the loading progress of the Page class? If i can get the loading information I now how to make the preloader, but how do I collect loading data? I know how to do it with external assets (swfs) and so on, but how to do it like this?

Sincerly Espen

View Replies !    View Related
[MX] Referencing A Dynamically Created MovieClip...
Hi,

I'm trying to load jpegs named Image1.jpg, Image2.jpg, etc, into dynamically created MovieClips using the following.

PHP Code:



TotImgs=number(myVars.TotImgs);
this.createEmptyMovieClip("ImageHolder"+TotImgs, 999);
loadMovie("Image"+TotImgs+".jpg", ["ImageHolder"+TotImgs]);




This, of course only loads one image, image3, but I just wanted to get the code correct before I start adding loops.

It ain't working but hopefully from the description of what I'm trying to achieve, somebody may be able to point me into the right direction.

The TotImgs variable loads fine, just no image loads in to the empty Movieclip.

Ta.

View Replies !    View Related
Referencing Dynamically Created Buttons
I am creating a set of buttons from an array of information and need to know how to reference those buttons after they are created. I've clearly got some sort of syntax error and it's driving me nuts.

Here's the function (within a ProdSelectSystem class) that creates the buttons (which works just fine. The buttons work and do what they are supposed to do):


Code:
//--------------------------------------------------------------------
public function doInit(_systemData:Array):Void
{
systemData = _systemData;
listItems = new Array();
attachButtonItems();
}

//---------------------------------------------------------------------
/*
Attach a button clip for each data item in our systemData array
call init() on the new clip passing it an ID and data items
*/
private function attachButtonItems():Void
{
var exportName:String = "mcNLProdButton";

for(var i:Number = 0; i < systemData.length; i++)
{

var item:MovieClip = this.attachMovie(exportName, "Item_" + i, i);

item.init(this, i, systemData[i]);

listItems.push(item);

} //end for
} //end function
The problem comes when I try to reference these buttons later elsewhere. Since the instance name given in the loop via the this.attachMovie is "Item_" + i, I was under the assumption that I could use (for example for the _alpha property of the second created button) _root.Item_1._alpha. When I try that, however, I get "undefined".

I'd appreciate all thoughts on the subject.
TIA,
CP

View Replies !    View Related
Referencing An Object Created By A Function
Why can't I reference an object created by a function if it has been added to the stage?

For example, I write a function that creates a text field and adds it to the stage:


ActionScript Code:
function makeText():void
{
    var myText:TextField = new TextField();
    addChild(myText);
}

Now in another function I want to say myText.text = "Hello!", but I get the error "1120: Access of undefined property myText.".

I know it has to do with scope, but how do you access something that's been added to the stage outside of the function that created it?

View Replies !    View Related
AS3 - Referencing Dynamically Created Variables.
Here I have a number of 'TweenField' instances created in a for loop. The problem is that each time the loop increments, the 'myTweenField' variable has the same name, so I don't know how they can be referenced individually from elsewhere in the script. How can I rewrite it so that each instance has a unique name, and how would I then reference it from outside the loop?


Code:
package
{
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
import com.TweenField;

public class LoadItems extends Sprite{
private var yy:Number=1.5
private var externalXML:XML;
private var someXML:XMLList

public function LoadItems() {
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("xmlFile.xml");
loader.load(request);
loader.addEventListener(Event.COMPLETE, onComplete);
}

public function onComplete(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
externalXML = new XML(loader.data);
someXML = new XMLList(externalXML.children().attribute("label"));
var bool:Boolean = true;
for(var xx:Number = 0; xx < someXML.length();xx++) {
if (bool) {
var myTweenField:TweenField = new TweenField(xx, someXML[xx], xx*30, 600, yy*30, 0, 20, .1, 200, yy*20, 1, 0, 1);
bool=false;
} else {
var myTweenField:TweenField = new TweenField(xx, someXML[xx], xx*30, -300, yy*30, 0, -20, .1, 200, yy*20, 1, 0, 1);
bool=true;
}
addChild(myTweenField);
yy++;
trace(bool);
}
}

private function saySomething(e:Event):void {
trace("changed");
}
}
}
Fingers

View Replies !    View Related
Referencing Dynamically Created Instances
I'm not even sure if I've described this problem correctly. Basically in one of my classes, I have a function that takes an array and generates a tile map from that (tile based game). Anyways, once I create my tiles, the variables used to make them are gone, since they were locally scoped, but the MovieClip instances are still in the display list (which is what I want). Now how can I reference these display objects by name? Here's the code to generate the map, if it helps:

for(var i:uint = 0; i < mapHeight; ++i) {
for(var j:uint = 0; j < mapWidth; ++j) {
this["t_"+i+"_"+j] = new tile();
mapContainer.addChild(this["t_"+i+"_"+j]);
this["t_"+i+"_"+j].x = (j*tileW);
this["t_"+i+"_"+j].y = (i*tileH);
this["t_"+i+"_"+j].gotoAndStop(map[i][j]+1);

}
}

View Replies !    View Related
Referencing Instances Created With AttachMovie
Hi,

I have a situation where I create many instances of an MC, one for each node in an XML file (using a for loop), using attachMovie.


Code:
var photo_mc = _root.center_mc.photosLevel1_mc.attachMovie("photoFrame_mc", photoName, itemCount);
Then later, but still inside the "for" loop, I refer to these instances with the variable to create an onRelease function for all of them:


Code:
photo_mc.onRelease = function() {
//stuff happens here
}
Now, elsewhere in the code, I need to activate the onRelease for one specific instance, so I can't use photo_mc but instead I have to do something like:


Code:
_root.center_mc.photosLevel1_mc.myInstanceName.onRelease();
For some reason this isn't working? What am I doing wrong? When I try to implement this the onRelease doesn't work at all and the Flash file seems to kind of hang or freeze up.

To complicate matters further, the instance name of MC I'm calling here is going to be a variable, so I will also need to know the proper AS notation to write that last line of code with the instance name being a variable. Is it something like?:


Code:
_root.center_mc.photosLevel1_mc.['varName'].onRelease();
All this confusion I'm having stems from trying to implement SWFAdress (http://www.asual.com/swfaddress/) into my flash file but my navigation is not straight-forward at all so it is making things VERY complicated. I've got the address and titles properly updating, but I can't quite get the SWFAddress.onChange function to work (this is where I am trying to put the above code, the variable being the SWFAddress.getValue(), which will supply the proper instance name to trigger the onRelease.

Any help here would be greatly appreciated! I'm pulling my hair out here!

View Replies !    View Related
Referencing Dynamically Created MovieClips
Hello and sorry for asking what is a horribly naive question, but I'm very new to ActionScript 3 and not really a coder. Any help is greatly appreciated!

So, if I did something like this:


Code:
for (var i:uint=0; i<10; i++)
{
var image:MovieClip = new MovieClip();
this.addChild(image);
}
Am I right in thinking that I just dynamically created 10 MovieClips and added them to the stage?

And if that is correct, how do I then reference each of those MovieClips, so that I can do stuff like load images into them and find out how wide they are etcetera?

Many thanks!

Chris

View Replies !    View Related
Referencing Dynamically Created Movieclips
ok so i want to creat an empty movieclip on the main stage, then create a textfield inside of that clip

whats the best way to reference these after i have created them.

i am currently using this code

Code:

var mc : MovieClip = createEmptyMovieClip( "m" + i , getNextHighestDepth() );
      mc._y = ( mc._height + 20 ) * i;
      mc.createTextField( "text" + i , i , 50 , 50, 500 , 20 );
         
      var txtFormat:TextFormat = new TextFormat();
         
      with ( txtFormat )
      {
         font = "Verdana";
         size = "10";
         bold = true;
         color = 0x000000;
      }
      
      with ( mc["text" + i] )
      {
         text = topics[i].attributes.name;
         setTextFormat( txtFormat );
         selectable = false;
      }


is there a better way to do this, without using the mc clip?

View Replies !    View Related
Controlling Multiple MC Created At Runtime
Hello,
I have the code below to create MCs at runtime:

MC.duplicateMovieClip("MC"+i,MC.getNextHighestDept h(),{_x:210});

how to controll them in a loop?

for(i=1;i<10,i++) {
MCi._x=i*150;//how to change _x position for each movie created?
}

View Replies !    View Related
Referencing A Variable Created In A Diff. Swf File
I have two swf files linked to one another via a loadMovieNum
("new.swf", 0); call

in this first swf I have created a variable in the main timeline (x)
that I want to be able to use in the 2nd swf file

how do i reference this variable in the new file?

View Replies !    View Related
Referencing Audio Created From Action Script
I have two movie clips. In each clip I have 1 frame with an action. In this action I call a function to attach a sound and play the sound.

For some reason when I reference one of the newly created sounds to alter its volume, the volume of the other audio track is altered. I read that you cannot reference clips individually if they are on the same time line?

I use _root.leftaudio.setVolume to alter the left and _root.rightaudio.setVolume.

Any tips?

View Replies !    View Related
Referencing Dynamically Created Instances Of Class
I've looked up several links but can't figure out why I can't access my dynamically created instances of class in as3... my code is...


Code:
var textPara:textPara1 = new textPara1();

content.addChild(textPara)
textPara.name = "bab"


var maxIndex:Number = content.numChildren - 1;
content.setChildIndex(content.bab as MovieClip, maxIndex);
content.bab.y = 50;
content.bab.x = 500
;


It adds an instance of the "textPara1" class (which I've put in the variable placeholder "textPara") to the display list of the "content" movieclip...

but despite assigning the new instance the name "bab", I can't seem to be able to access it (i.e. when i want to set the x and y position).

I thought it might have something to do with using array [i.e. square brackets] syntax, but already tried that to no avail.

My other thought was maybe I have to write in some sort of code that makes sure the instance has loaded to the stage/display list first and then write and function which references only after that has happened... but I could be talking nonsense!

Please please help. Any thoughts/links very very appreciated.
Cheers.

View Replies !    View Related
NoobAlert: Dynamically-created Object Referencing
Long-time Flash user, new Actionscript student, so please forgive my forum invasion with what is probably a simple-answer type of question.

If I drop instances directly on the stage, I can access and modify their attributes and built-in functions just fine by referring to the instance name I specified.

However, if I use the constructor to make and position a group of objects at runtime, later attempts to reference or modify those objects by name generate an "Access of undefined property ..." error. I can modify the names in a loop within the constructor and trace their names to verify, but no luck actually accessing them. Am I missing something? (Other than a couple of months of reading, studying, implementing, and experimenting)

Thanks for any direction!

View Replies !    View Related
About Referencing Objects And Copying Objects
This is for AS1

hi,

i should know this but i got lost for a bit, can someone make this clear:

i have the following:

code: myobject=new Object()
myobject.var="hello"
getvar=myobject.var

In this case, get var has a reference for myobject.var, or it has just copied de value? mean if i update myobject.var to "good bye" get vatr will be that, too, or will stay as "hello".

If it's just a reference, how can make it a different variable, i mean, assign the value of myobject.var to getvar and loose any relationship between myobject.var and getvar, so if i update one, the other doesn't.

Anyone?

View Replies !    View Related
Controlling Runtime Created Movie Clips.
Hi all.

I'm new to flash and am having some troubles with runtime created movie clips. I have a movie clip which on its first frame calls stop(). I create these movie clips at runtime by doing:

attachMovie("libraryname", "newname", this.getNextHighestDepth());

This works fine, but when I try to make it play the second frame with the following code:

this["newname"].gotoAndPlay(2);

Nothing happens. I was hoping for someone to point me in the way of a tutorial for this area, or just tell me what I'm doing wrong here. I've tried looking around for tutorials and other peoples movies but no luck as of yet.

Thanks in advance.

Andrew Starnes

View Replies !    View Related
Nesting Dynamically Created Movieclip At Runtime?
Is it possible to nest a movieclip into another dynamically created movieclip at runtime? The commented line of code works, but I am trying to nest a movieclip after it is created into another.







Attach Code

this.createEmptyMovieClip("House_mc", 1);
//this.House_mc.createEmptyMovieClip("Dog_mc", 2);
this.createEmptyMovieClip("Dog_mc", 2);
trace(this.House_mc.Dog_mc);

View Replies !    View Related
DONT KNOW : How To Resize A Movieclip Created At Runtime
I don't know how to resize a movieclip created at runtime......











Attach Code

// Creates a parent movie clip to hold the container.
this.createEmptyMovieClip("my_mc", 1);

// Creates a child movie clip inside of "my_mc".
// This is the movie clip the image will replace.
my_mc.createEmptyMovieClip("container_mc",1);

//Show error when i run the below width & height statements.
//my_mc._width=100;
//my_mc._height=100;

// Use MovieClipLoader to load the image.
var my_mcl:MovieClipLoader = new MovieClipLoader();
my_mcl.loadClip("F:\Test\Flash\XML SLIDE show\pic\5.jpg", my_mc.container_mc);

//setProperty did'nt also work
//setProperty("my_mc.container_mc", _width, 45);

// Put event handler on the my_mc parent movie clip.
my_mc.onPress = function():Void {
trace("clicked "+pc);

//Width and Height changes only when i place the code in onPress EVENT
my_mc._width=100;
my_mc._height=100;
};

View Replies !    View Related
Mask A Runtime Created Gradient Fill
I m having problems in masking a gradient fill created at runtime. Actually i had a movieClip an then at runtime created three movieClips
1.gradient filled rectangle mcGrad,
2.loader to load an image mcLoader
3.a curved rectangle mcMask

trying to mask mcGrad and mcLoader with mcMask
image gets masked but mcGrad not, i m writing as-:

mcGrad.setMask(mcMask);
mcLoader .setMask(mcMask);

View Replies !    View Related
Referencing A Var Within A Dynamically Created Button Via An Attached Function
I'm having a issue using a var within a button.
I create the button and add the var to the to button:

addChild(answerButton);
answerButton.thisX = ii; // temp value that changes with each addchild

The Question is how do I get the buttons to trace (to start with) the value of the var contained within them?

So easy in as 2


Here is my code below:



PHP Code:




//matchingSetUp.as
package {
    import flash.display.Sprite;
    import flash.text.*;
    import flash.events.MouseEvent;
    import flash.display.MovieClip;

    public class matchingSetUp extends Sprite {
        private var choiceButton:choice;
        private var allAnswers:Array;
        private var answerButton:answer_box;
        private var tempString;//my movieclip name
        private var myThis:MovieClip;//my movieclip
        private var sortMethods:Array = [1,2,8];// 3 diverse types of sorts
        var sortInt:int=0;
        private var _matchingObj:Object;
        public function matchingSetUp(_matchingObj) {
            init(_matchingObj);
        }
        private function init(_matchingObj) {
            // setting up drop zones
            for (var i:int=0; i < _matchingObj.problemCodes.length; i++) {
                choiceButton=new choice  ;
                addChild(choiceButton);
                choiceButton.x=_matchingObj.targetsX;
                choiceButton.y=_matchingObj.targetsY[i];
                choiceButton.name="mc" + _matchingObj.problemCodes[i];
            }
            //setting up Correct answer buttons
            //// putting all answer into 1 array
            allAnswers = _matchingObj.choiceBank;
            for (var k:int = 0; k< _matchingObj.extraChoices.length; k++) {
                allAnswers.push(_matchingObj.extraChoices[k]);
            }
            //// pseudo-randomizing the answers boxes based on sorts
            sortInt = (Math.random() * 3);
            allAnswers.sort(sortMethods[sortInt]);
            //// adding the boxes to the stage
            for (var ii:int=0; ii < allAnswers.length; ii++) {
                answerButton=new answer_box  ;
                addChild(answerButton);
                answerButton.x=757;// this needs to be in the fla struct
                if (ii == 0) {
                    answerButton.y=108;// this needs to be in the fla struct
                } else {
                    tempString =allAnswers[ii-1];
                    myThis=answerButton.parent.getChildByName(tempString)  as  MovieClip;
                    answerButton.y=myThis.y + 29;
                }
                answerButton.name=allAnswers[ii];
                answerButton.thisX = ii;
                trace(answerButton.thisX);                myThis=answerButton.parent.getChildByName(answerButton.name)  as  MovieClip;
                myThis.my_name.text = allAnswers[ii];
                answerButton.addEventListener(MouseEvent.CLICK,myMouseDown2);


            }
        }

        private function myMouseDown2(event:MouseEvent):void {
            trace(thisX); // how do I access the var here ??????????????????????????
        }
    }
}

View Replies !    View Related
Referencing/loading A Dynamically Created Movieclip Variable
Hi there,

Its my first post, but I'm hoping someone out there can help me!

I am trying to load an image in to a dynamically created movieclip, which is:

_root.mySlider."+stripX2(band[i][0])+i

but I can't seem to reference it. I can load the movie into _root.mySlider, but if I add the dynamic element (stripX2(band[i][0])+i) without quotes it it doesn't load. If I load with quotes

i.e.

"_root.mySlider."+stripX2(band[i][0])+i

flash doesn't allow strings in movieClip variables


The code I'm using is belowm, it's the second to last line thats causing the problem:

var loadListener:Object = new Object();
loadListener.onLoadComplete = function(target_mc:MovieClip):Void {
trace(">> target_mc._width: "+target_mc._width);
};
loadListener.onLoadInit = function(target_mc:MovieClip):Void {
trace(">> target_mc._width: "+target_mc._width);
};
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(loadListener);
var mc:MovieClip = _root.mySlider.createEmptyMovieClip("mc", this.getNextHighestDepth());

mcLoader.loadClip(inBead.bead_loc, mc);


Many Thanks!

View Replies !    View Related
My Runtime Created Empty Mc Doesn't Respond To Event
Hi everybody! I'm kinda new at actionscript so pls excuse me if I'm sounding a little stupid or asking the obvious okay. I'm creating a thumbnail viewer where the thumbnails should become clickable. I'm first using createEmptyMovieClip for the clickable area, then I place another Mc inside of it in which I load the image file.

It all works so well if I make just one instance of it but as soon as I'm starting to loop I cannot get it to respond to onRelease or any other event for that matter.

_root["home_mc" + count].onRelease = function()
{
trace("Nobody clicks me!!!!!!");
}

What am I missing here?
Could somebody pls enlighten me before I start drawing my clips again?

View Replies !    View Related
Referencing Objects In A Different SWF
I'm attempting to create my first all-Flash web site. I have a master SWF that will load other SWFs into movie clips or levels.

One of the SWFs I plan to load is a complex menu system. When certain buttons in the menu are selected, I want things to happen in the master SWF file (i.e. other SWFs and text files load). Is there a way to reference objects in the master SWF from the menu SWF? Or is there a way to reference objects in the menu SWF from the master SWF? If both are possible, which way is better?

View Replies !    View Related
Referencing Objects
Is there any way to refernce multiple objects with similar names using a loop?

eg button1, button2, button3
code:
for (i=1; i<=3; i++ ) {
button(i)._visible = false;
}

View Replies !    View Related
Referencing Objects From AS2 Swf Into AS3 Swf
I load AS2 swf into AS3 swf.
Is there a possibility to reference Document Class methods or properties from external loaded AS2 swf?


Cheers,

View Replies !    View Related
[AS2] Referencing Objects
I have an object called H with a property of mc set equal to hero:


ActionScript Code:
var H:Object = new Object();
H.mc = "hero";


the property mc holds the name of the movie clip the object H deals with

I am trying to retrieve the y coordinate of the movie clip here
I have tried the following but it dont work


ActionScript Code:
function Move(Object) {
trace( this[Object + ".mc"]._y );
}
 
Move("H");

View Replies !    View Related
Referencing Of Array Objects
Hello!
I don't know how many ties I've had this d*mn problem but it never fails - I can't get it to work. Lemme tell you what I am TRYING to do.

I have an array that randomly generates numbers (14). No problem. I call the array alpha cause it controls alpha levels and such (this doesn't matter). I also have a MC on the stage called mc_oval. After each loop (14 of them) - count has one added to it. I want to be able to able to duplicate the mc_oval MC and call each new MC "mc_oval" + count. Each new level is count +1 (so we don't replace level0.

the problem comes when I go to position the dynamic clip. Here is my code:


Code:
n = 14;
count = 0;
alpha = new Array();
while (count<n) {
alpha[count] = randomNum=Math.round(Math.random()*99+1);
//
duplicateMovieClip (_root.mc_oval, "mc_oval_"+count, count+1);
setProperty ("mc_oval_"+count, _x, "25");
count++;
}
Now I have tried this eval() sh*t but it works werid and doesn't fix the problem. I've tried:

eval("mc_oval_" + count);
and
"" + eval('mc_oval_' + count);

I'm lost - please help me!

View Replies !    View Related
Referencing Objects Via An Array
hello

i am trying to create a fake email inbox for an eLearning simulation. the brief is thus:

the inbox lists emails. emails are added as the user progresses through the game. for each email, its variables are displayed (from, subject, date received).

i have an array to store the emails in, and an index to keep count:


Code:
// Keeps track of number emails so that they can be put into an array
//and referenced.
emailCount = 0;

// Array to store emails in.
emails = new Array();


i have a constructor to create a new email object:


Code:
function email(newID, newFrom, newSubject, newBody, newDate) {
ID = newID;
emailCount ++;
from = newFrom;
subject = newSubject;
body = newBody;
thisDate = newDate;
read = false;
emails.push(ID);
}


i also have a function to display the emails:

Code:
displayEmails.onPress = function() {
for(i = 0; i < emails.length; i++) {
attachMovie("emailListMember", ["emailListMember" + i], i);
with(["emailListMember" + i]) {
from = _root.emails[i].from;
subject = _root.emails[i].subject;
thisDate = _root.emails[i].thisDate;
ID = _root.emails[i].ID;
_x = 30;
_y = 30 * i + 10;
}
}
}


after creating a couple of email instances, and trying to display them, i find their variables are not set. i think its because the array values do not point to the email instance itself, and merely holds a string.


cheers in advance

View Replies !    View Related
Dynamically Referencing Objects
I have generated movie clips with nested textboxes inside inside a dynamic for loop (.createEmptyMovie and .createTextBox).I do this by generating a name with the counter added to it ("mc" + x or 'txtbox" +x) -- Which generates (mc1, mc2,..., txtbox1, txtbox2,...)

I am having troubles trying to reference these individual objects with in the loop to set a value to them (_root.mc[x] and _root.mc[x].txtbox[x]). This attempt doesn't work. If I hard code a number in place of the "[x]" my code runs correctly. I am trying to reference them dynamically because I am reading from a file that could be any length long and I do not want to have to update the fla file any time a new item is added.

Does anyone know how if I could possibly get these objects referenced dynamically or if you need a definite reference to the objects? Thank you

View Replies !    View Related
[F8] Referencing Array Of Objects
Ive done this before, but I forget teh notations. I have objcts date1,date2..... save as a movieclip dateBoxes. I cant remember how to referencec them, say, in a for loop.

for (i=0; i==10; i++) {
dateBoxes.["date" + i].text = i;
}

Like that but it has to work lol.

thanks in advance.

View Replies !    View Related
Two Objects Referencing Same Array?
I'm working a neural network project and my basic architecture is this:
1. Neurons
2. Neuron Layer (basically an array of neurons)
3. Neural Network (basically an array of Neuron Layers)

When I reference the first Neuron Layer's array.length it gives me the total number of neurons in the network rather than what the number of neurons in the first layer should be. The same thing happens for the second layer and each subsequent layer should there happen to be more. I've added trace statements to the Neuron Layer constructor that tells me a neuron has been added and I've also added a trace statement after the first neuron layer is added and the second neuron layer and I get the correct number of "neuron added" statements before the "first layer added" statement and the correct number for the second layer as well. This pretty much assures me that the actual number of neurons in each layer is correct when the first layer is created but somehow the number of neurons in the first layer and subsequent layers is actually becoming the number of neurons total. The only thing I can figure out is that somehow, the first neuron layer object is referencing the same neuron array member as the second neuron layer object. Is this possibly what is happening?

Here's the code for the Neuron Layer class:

Code:
import Neuron;

class NeuronLayer{
//number on neurons in layer
private var numNeurons:Number;
//array of neurons
private var neurons:Array=new Array();
//number of inputs per neuron
private var numInputsPerNeuron:Number;

//constructor
public function NeuronLayer(numOfNeurons:Number,numOfInputsPerNeuron:Number)
{
numNeurons=numOfNeurons;
numInputsPerNeuron=numOfInputsPerNeuron;
for(var i=0;i<numNeurons;i++)
{
var neuron:Neuron=new Neuron(numInputsPerNeuron);
neurons.push(neuron);
trace("Adding Neuron");
}
}

//function to get the num of neurons in layer
public function getNumNeurons():Number
{
return numNeurons;
}

//function to get the num inputs per neuron
public function getNumInputsPerNeuron():Number
{
return numInputsPerNeuron;
}

//function that returns a copy of the neuron array
public function getNeuronArray():Array
{
var neuronArray:Array=new Array();
neuronArray=neurons.slice();
return neuronArray;
}
}
And here's the code for the Neural Network Class:


Code:
import Neuron;
import NeuronLayer;

class NeuralNetwork{
//number of inputs for network
private var numInputs:Number;
//number of outputs for network
private var numOutputs:Number;
//number of hidden layers
private var numHiddenLayers:Number;
//neurons per hidden layer
private var numNeuronsPerHiddenLayer:Number;
//array of neuron layers
private var neuronLayers:Array=new Array();
//activation response constant
private static var P_SETTING:Number=1;

//constructor, initializes private members for this class and call createNet
//function
public function NeuralNetwork(inputs:Number,
outputs:Number,
hiddenLayers:Number,
neuronsPerHiddenLayer:Number)
{
numInputs=inputs;
numOutputs=outputs;
numHiddenLayers=hiddenLayers;
numNeuronsPerHiddenLayer=neuronsPerHiddenLayer;
createNet();
}

//function that gets the number of inputs
public function getNumInputs():Number
{
return numInputs;
}

//function that get the number of outputs
public function getNumOutputs():Number
{
return numOutputs;
}

//function that gets the number of hidden layers
public function getNumHiddenLayers():Number
{
return numHiddenLayers;
}

//function that gets the number of neurons per hidden layer
public function getNumNeuronsPerHiddenLayer():Number
{
return numNeuronsPerHiddenLayer;
}

//function that returns a copy of the neuron layer array
public function getNeuronLayerArray():Array
{
var neuronLayerArray:Array=new Array();
neuronLayerArray=neuronLayers.slice();
return neuronLayerArray;
}

//builds network from neurons
private function createNet():Void
{
//create layers of network
if(numHiddenLayers>0)
{
//create first hidden layer
var firstHiddenLayer:NeuronLayer=new NeuronLayer(numNeuronsPerHiddenLayer,
numNeuronsPerHiddenLayer);
//push it into the neuron layer array
neuronLayers.push(firstHiddenLayer);

trace("Added first layer");

//create other hidden layers as necessary
for(var i=0; i<numHiddenLayers-1; i++)
{
var hiddenLayer:NeuronLayer=new NeuronLayer(numNeuronsPerHiddenLayer,
numInputs);
neuronLayers.push(hiddenLayer);

trace("Adding Additional layers");
}

//create output layer
var outputLayer:NeuronLayer=new NeuronLayer(numOutputs,
numNeuronsPerHiddenLayer);
neuronLayers.push(outputLayer);

trace("Added output layer");
}
else
{
//create output layer
var defaultOutputLayer:NeuronLayer=new NeuronLayer(numOutputs,
numInputs);
neuronLayers.push(defaultOutputLayer);
}

}

//function that returns all the weights in the network as an array
public function getWeights():Array
{
var weightArray:Array=new Array();
for(var i=0; i<neuronLayers.length; i++)
{
for(var j=0; j<neuronLayers[i].getNumNeurons(); j++)
{
weightArray.concat(neuronLayers[i].getNeuronArray()[j].getWeights());
}
}
return weightArray;
}

//function that returns the total number of weights in the network
public function getNumWeights():Number
{
var total:Number=0;
for(var i=0; i<neuronLayers.length; i++)
{
for(var j=0; j<neuronLayers[i].getNumNeurons(); j++)
{
total+=neuronLayers[i].getNeuronArray()[j].getWeights().length;
}
}
return total;
}

//replaces old weights with new weights
public function putWeights(weights:Array, newWeights:Array):Void
{
//empties array that's passed
weights=[];

weights=newWeights.slice();
}

//sigmoid response curve applier
public function applySigmoid(activation:Number,responseSetting:Number):Number
{
return 1/(1+Math.pow(Math.E,(-activation/responseSetting)));
}

//calculate outputs from set of inputs
public function update(inputs:Array):Array
{
//stores the resulting outputs from each layer
var outputs:Array=new Array();

var weightCounter:Number=0;

//check for correct number of inputs
if(inputs.length!=numInputs)
{
//just return empty vector if incorrect
return outputs;
}

//for each layer
for(var i=0;i<numHiddenLayers+1; i++)
{
if(i>0)
{
//copies elements into the array
inputs=outputs.slice();
}

//clears array of values
for(var a=outputs.length;a>=0; a++)
{
outputs.pop();
}

weightCounter=0;

//for each neuron sum the inputs*corresponding weights
//throw the total at the sigmoid function to get the output
for(var j=0;j<neuronLayers[i].numNeurons;j++)
{
var netInput:Number=0;

var numOfInputs:Number=neuronLayers[i].neurons[j].numInputs;

//for each weight
for(var k=0; k<numOfInputs-1; k++)
{
//sum of the weights*inputs
netInput+=neuronLayers[i].neurons[j].weights[k]*inputs[weightCounter++];
}

//add in the bias
netInput+=neuronLayers[i].neurons[j].weights[numOfInputs-1]*-1

//we can store the outputs from each layer as we generate them.
//The combined activation is first filtered through the sigmoid
//function
outputs.push(applySigmoid(netInput, P_SETTING));

weightCounter=0;
}
}
return outputs;
}
}

View Replies !    View Related
Referencing Objects Within MovieClips
Hey guys, I need some help. I'm new to Flash/Actionscript and what I'm trying to do seems like it should be straight-forward and very common, but for the life of me I can't figure it out.

I've created a MovieClip in the Flash editor called 'MyClip'. As part of this movieclip there is some dynamic text.

I've also defined an ActionScript class for MyClip that inherits from MovieClip. In it there is a member function DisplaySomeText(myText:String). How can I get this function to set the dynamic text that is part of my movieclip?

At first I thought I could just give the dynamic text an instance name (say 'MyTextField') and go:


Code:
public function DisplaySomeText(myText:String)
{
this.MyTextField.text = myText;
but that doesn't work.

How the heck do you do this??

Thanks in advance for any help,
Oliver

View Replies !    View Related
Referencing Duplicates From Other Objects...
...is there a way to do it? If so, say I have two movie clips A and B, and I've made duplicates of A. How can I reference each A from:
1. Any of the other A duplicates? and
2. The B movie clip?

What is the scoping syntax for that? I tried to use _root.{the name of A duplicate}.{property} for accessing A from B but it didn't seem to work.

View Replies !    View Related
Referencing Objects On Stage
Ok, this is a dumb question but I'm just horribly stuck.
In my script I go toframe 5, and there are several textfields and clips on stage, but I can't reference them from my code. I get an error saying the objects don't exist.
If I move the objects of stage and just move them into place later that works but I'm pretty sure there is a better way to do it.

Any thoughts or links? I've checked around google but I don't know exactly what I should be searching for here.

View Replies !    View Related
Referencing Objects On Separate Timelines
If I have a dynamic textbox that exists only on the last frame of a movieclip and I need to set the text for it from the main timeline, how would I reference it? I tried referencing it by going mc.hint_mc.hintText_txt.text = "Bla" but that doesn't work and I realized that could be because the textbox only exists on one frame of the movieclip. Is there a way to do this?

View Replies !    View Related
Having A Problem Referencing Objects On Stage ?
Hi everybody,

I am having a problem referencing two objects on stage and telling them to swap depths. I have an object called "illustration" on the stage that has two separate layers inside of it. These two layers hold "illustrationText" and "illustrationTextRed". My problem comes when I try to swap the depth of the two child objects (illustrationText, illustrationTextRed).

The code I placed on the timeline:


PHP Code:



illustration.addEventListener(MouseEvent.ROLL_OVER, onIllustrationOver);
illustration.addEventListener(MouseEvent.ROLL_OUT, onIllustrationOut);

function onIllustrationOver(event:MouseEvent):void
{
    root.illustration.swapChildren(illustrationText, illustrationTextRed);
}

function onIllustrationOut(event:MouseEvent):void
{
    root.illustration.swapChildren(illustrationText, illustrationTextRed);





Compiler errors keep getting thrown:
Access of undefined property illustrationText
Access of undefined property illustrationTextRed

Am I going about this the right way?

Thanks for your help!

-Brian

View Replies !    View Related
Referencing Display Objects From An Array
Hi

My Psuedo Code:


Code:
myArray = [MC_01, MC_02, MC_03]

for (arrayLength){
myArray[i].addEventListener(MouseDown)
}

Listener(evt) {
stage.addChild(evt.target) //To bring Clicked MC to top of display list
}

Basically what i'm doing is having my array of MC's jumbled on the stage and when I click I want it to come forward. The way I have made objects move to the top previously is using addChild again on it... and it worked fine. With my code i'm getting

1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.displayisplayObject.

as I try to addChild again. How do I reference the MC properly and make it jump forward properly? I cna't seem to work it out.



Thanks in advance
Jethro

View Replies !    View Related
Importing Objects For Runtime Sharing
i'm having some trouble importing objects for runtime sharing. i right-click on the object in the library, select linkage, check import for runtime sharing, and specify the URL of the movie that exports the object.

the URL, in this case, is main.swf, but if i type that into the URL field, click ok, and then reopen linkage, the URL field is blank!

if i input any other URL (e.g. main1.swf or whatever.swf or even fkgjfkjg), the URL will remain there. for some reason, it won't let me specify main.swf.

anyone know why??

i've done it before, why can't i do it know?

View Replies !    View Related
Resizing Objects At Runtime With Mouse
I want to put together a web site entirely with flash. On one page, I will be displaying pictures with a description beside them. (Each description may be several paragraphs long.)

I want the user to be able to left click the mouse and pull the picture size to a larger size. (It is okay if this process overlaps the description, although it might be nice to have 'splitter window' functionality where the description is also resized.)

Where can I find documentation on how to do this?

View Replies !    View Related
Creating Linkable Objects On Runtime
Creating classes and specifying linkage in the library, everything works fine.
But, I want to do this without using the library.
I'm pretty sure registerClass is the way to do this, but all I get as a return is "undefined" when I call it.

Here's an example:

Code:
// bleh.as
class bleh extends MovieClip {
public function bleh() {
this.onRelease = function() { trace('boo'); }
}

public var some_mc:MovieClip;
}

// test.fla
var okok = new bleh();
okok.some_mc.registerClass( 'some_mc', MovieClip )

// and then something like...
while i < 1000
_root.attachMovie( "some_mc", 'tile_inst'+i+j, layer++ );
This doesn't work, and I'm 99.99% sure I'm using registerClass the wrong way

View Replies !    View Related
Creating Linkable Objects On Runtime
Creating classes and specifying linkage in the library, everything works fine.
But, I want to do this without using the library.
I'm pretty sure registerClass is the way to do this, but all I get as a return is "undefined" when I call it.

Here's an example:

Code:
// bleh.as
class bleh extends MovieClip {
public function bleh() {
this.onRelease = function() { trace('boo'); }
}

public var some_mc:MovieClip;
}

// test.fla
var okok = new bleh();
okok.some_mc.registerClass( 'some_mc', MovieClip )

// and then something like...
while i < 1000
_root.attachMovie( "some_mc", 'tile_inst'+i+j, layer++ );
This doesn't work, and I'm 99.99% sure I'm using registerClass the wrong way

View Replies !    View Related
Importing Objects For Runtime Sharing
i'm having some trouble importing objects for runtime sharing. i right-click on the object in the library, select linkage, check import for runtime sharing, and specify the URL of the movie that exports the object.

the URL, in this case, is main.swf, but if i type that into the URL field, click ok, and then reopen linkage, the URL field is blank!

if i input any other URL (e.g. main1.swf or whatever.swf or even fkgjfkjg), the URL will remain there. for some reason, it won't let me specify main.swf.

anyone know why??

i've done it before, why can't i do it know?

View Replies !    View Related
Referencing Dynamically Loaded Clips/objects
I've been playing around with building a tile based game after checking out a couple tutorials.. I've established an overhead level with a moveable character and static objects within that environment. My problem is, that I can't seem to properly reference the character or objects (enemy0-7) within a function of the frame. I've tried a variety of possible references (_root.clip.char, etc..) to no avail.. I've attached the FLA (put the map below). Anyone have any ideas?

Thanks,
Shawn

the map is a text file named map.as located in the same folder as the swf.. map works fine.. Here's what's in map.as:

map = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,1,1,1,1,0,1,1,0,0,1,1,1,0,1,1,1,0,1],
[1,0,1,1,1,1,0,1,1,0,0,1,1,1,0,1,1,1,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] ];

// startPosition [x,y]
startPos = [9,14];

// enemys startPositions [x,y]
enemys = [[2,1],[18,2],[9,8],[6,15],[12,18],[10,12],[15,15]];

View Replies !    View Related
Simple Problem - Referencing Objects By Variable Name
I have a simple function that dynamically creates text fields. My text field name is referenced by var thisTextField. Problem is, when i try to do things with my text field, actionscript shoots back an error as such:

There is no property with the name 'text'.

How am i supposed to apply properties to my object if my objects name is a variable?



Code:
function showProducts() {

var products:Number = 0;
var thisTextField:String = "product" + products + "_txt";

for (var itemID in _global.rtsData[_global.rtsPos]["products"]) {

this.createTextField(thisTextField,1,25,75,350,50);
trace(thisTextField);
thisTextField.autoSize = true;
product+products+_txt.text = _global.rtsData[_global.rtsPos]["products"][itemID]["products_name"];

products++;

}

_root.products_mc.gotoAndPlay("fadeIn");

}

View Replies !    View Related
Multiple Selection Of Text Or Objects At Runtime
see i am making a clone of http://businesscards.com/account/edi...1;category]=10 , now in my editor all the tools were working perfectly .

My problem is i dont know how to make undo/redo and multiple selection of text or objects in editor at runtime like as you see in http://businesscards.com/account/edi...1;category]=10, you can select mutiple text and objects at one time

Please see this site http://businesscards.com/account/edi...1;category]=10, you can understand what i want
I will really appricate if u help me

Thanks

View Replies !    View Related
[F2004] Problem In Importing Objects On Runtime
Hello guys!

i m working on flash offline application... i have a main file where i have hundreds of movieclips and sound clips to animate and run on the stage directly from libaray by "export for actionscript" and "export in fisrt frame". Everything is going well but the final swf file or projector file becomes very heavy and have problem runing on P2 system.

so , is it possible that i could divide the assets of movie i.e. sound clips and movie clips on saprate files ... and i load these files into main file time to time during runtime .. and use there sound and movie clips from the main file script.. i only want to use the resources of other files for actionscript...

Your kind attention is required

Cheers!

View Replies !    View Related
Preloader Not Loading Objects Added At Runtime
Morning! I'm very sorry, it's another preloader question...

My preloader is working fine, but objects that are added at runtime using attachMovie() don't show up, unless I tell them to export in first frame. Then, of course, my preloader sits on its arse until it's about 60% loaded, which isn't great. Might it be something to do with me having the movie split into a number of scenes?

This is my PL code, located on frame 2:

Code:

var percentLoaded = Math.round((_root.getBytesLoaded()/_root.getBytesTotal())*100);
loadingText = percentLoaded+"% loaded...";
if (_root.getBytesLoaded() != _root.getBytesTotal()) {
   gotoAndPlay(1);
}

TIA,
Tom

View Replies !    View Related
Copyright © 2005-08 www.BigResource.com, All rights reserved