[F8] Array And Classes
Hi,
I never had noticed that when you make one array equal another one, Flash keep them both dynamically tied...
For instances:
Code: OldArray = new Array(); NewArray = new Array();
OldArray[0] = "john"; trace (OldArray); // traces john
NewArray = OldArray; trace (NewArray); // traces john
OldArray[0] = "mary"; trace (OldArray); trace (NewArray); // traces mary / mary // but shouldnt trace john / mary? There is a way to avoid this problem, that is, "untie" the two arrays from each other?
Thanks in advance!
FlashKit > Flash Help > Flash ActionScript
Posted on: 10-04-2006, 01:50 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Array Of Classes
Hello!
I have a problem concerning the way you can create an array of objects. I created the class student:
function student(name,year) {
this.name=name;
this.year=year;
}
student_array = new student[10];//I think I've created here an array with 10 students
student[1].name="Flashy";//it's this corect???
Thank you!
Bogdan
AS1 How Do I Set Up An Array Of Classes?
heres my code for making one class
cwall = function () {
this.x = 0;
this.y = 0;
this.vwidth = 0;
this.vheight = 0;
};
_global.wall_A = new cwall();
what would i do to make _global.wall_A an array of classes?
also how would i call them?(i.e is it like _global.wall_A[2].x=5
AS1 How Do I Set Up An Array Of Classes?
heres my code for making one class
cwall = function () {
this.x = 0;
this.y = 0;
this.vwidth = 0;
this.vheight = 0;
};
_global.wall_A = new cwall();
what would i do to make _global.wall_A an array of classes?
also how would i call them?(i.e is it like _global.wall_A[2].x=5
Array Of Classes
I wanna make an array of classes and then access those classes through the array.
myArray = ["first","second"];
trace(myArray[0]); // first
theName = "first";
_root.attachMovie("theSymbol",theName, 100);
first.someFunction(); // this works
// I found that You can't do this:
theName.someFunction(); // Here, it thinks that 'theName' is an object; I want to use it's value instead.
// this doesn't work either
myArray[0].someFunction();
how can I make an array of classes u
For In Loop For An Array Of Classes
Hello,
I'm trying to figure out how I can use a for in loop to change all the boolean values of many instances of a custom class all at the same time.
ActionScript Code:
for(var i:Boid in boidArray)
{
i.go = goBool;
}
With this little bit of code, the goBool would equal true onMouseDown and false onMouseUp. So in turn, all the instances of the Boid class would be true onMouseDown and false onMouseUp.
Instead it gives me the error 1067:Implicit coercion of a value of type string to an unrelated type Boid.
The Boid class already exists and so does the "go" boolean. What are your thoughts?
F5: Array Of Objects/Classes?
I was wondering if I can create an array of created Classes. I have a
feeling that I cannot, and that you can only create an array of
values, not objects.
FMX: Array Of Classes Or Objects?
I'm trying to create an array of a particular class inside another
class. I believe my problems at this point are the array/class
declarations. The code below represents an example of what I'm
attempting, and not the actual application.
class c_one {
var a:Number;
var b:Number;
var c:Number;
}
class c_two {
var str1:String;
var str2:String;
var cOne_Array:c_one = Array(); <-----------?????????
function c_two () {
str1 = "Hello";
str2 = "there";
cOne_Array = new Array();
}
//End of class
}
I believe the tutorial also mentioned that the constructor needs
the "new Array" to make sure that each instance has a new copy
of an array. However, the compiler doesn't like this line.
I can comment out the constructor Array statement. However my
application code doesn't seem to recognize that an array exists if
I attempt to do the following:
var my_class2:c_two
my_class2.cOne_Array[1].b = 555; <----- undefined, according to Flash
Any help is appreciated.
F5: Array Of Objects/Classes?
I was wondering if I can create an array of created Classes. I have a
feeling that I cannot, and that you can only create an array of
values, not objects.
FMX: Array Of Classes Or Objects?
I'm trying to create an array of a particular class inside another
class. I believe my problems at this point are the array/class
declarations. The code below represents an example of what I'm
attempting, and not the actual application.
class c_one {
var a:Number;
var b:Number;
var c:Number;
}
class c_two {
var str1:String;
var str2:String;
var cOne_Array:c_one = Array(); <-----------?????????
function c_two () {
str1 = "Hello";
str2 = "there";
cOne_Array = new Array();
}
//End of class
}
I believe the tutorial also mentioned that the constructor needs
the "new Array" to make sure that each instance has a new copy
of an array. However, the compiler doesn't like this line.
I can comment out the constructor Array statement. However my
application code doesn't seem to recognize that an array exists if
I attempt to do the following:
var my_class2:c_two
my_class2.cOne_Array[1].b = 555; <----- undefined, according to Flash
Any help is appreciated.
Problems Referencing Classes From An Array
I am having a problem accessing public static constant arrays that are filled with class names from packaged files. all classes have access to each other within the package. I can access the array and see that there are multiple items in the array but are all null. if I access a const that is just the class it works fine just not when in an array.
PHP Code:
package samefolder{
public class c1{
public function c1(){
trace(c2.classArray.length) // displays 3
trace(c2.classArray[0]) // displays null
trace(c2.classArray[1]) // displays hello
trace(c2.classArray[2]) //displays [class int]
trace(c2.classConst) // displays [class c3]
}
}
}
package samefolder{
public class c2{
public static const classArray:Array = new Array(c1,"hello",int);
public static const classConst:Class = c3
public function c2(){
//some code
}
}
}
package samefolder{
public class c3{
public function c3(){
//some code
}
}
}
I have tried everything i can think of and am in need of some help.
Array Functionality Inside Classes
I have 4 defined private arrays defined in the constructor of my class.
Later down in one of the methods, im trying to push() variables into these arrays, but nothing seems to happen. I tried using this.arrayname.push(), but that doesn't seem to work either.
any ideas? do i need to manually push them by this.arrayname[arrayname.length+1] = "";
Vector And Matrix Classes As Extensions Of Array
Hey,
I wrote these vector and matrix artithmetic classes (along with a perspectiveMatrix class that puts them to use). They are attached (in the next post), and can also be found at:
homepage.mac.com/timsummers/index.html
If anybody wants to test them a bit, I'd be happy for feedback.
The perspective class takes lists of points in the form (x,y,z,1) and puts them through a pipeline. Right now the frustum is small, so it's best to plot x,y,z values that are from -1 to 1. You can change the frustum as a parameter.
I also have a renderer, which draws parametrically from vectors; if it's useful I could post that too, and some transform matrices, and maybe a primitive or two.
Thanks.
Assigning Tween Classes To Objects In An Array
oh man this is heavy
My array has a few objects that are revolving like on a carrousell...I want them to react on my mouseclick.
I cant seem to get this to work...
how would one make objects in an array do things?
I cant even define the path to them properly, it appears that I SUCK.
Allow me to present to you my little code-turdthat wont work in a million years
_level0.holder_mc.dot0.onRelease = function() {
var xScaleT:Tween = new Tween(kText, "_rotation", back.easeOut, 0, 1222, 2, true);
};
Id hugely appreciate some help...
Accessing Array In Document Class From Other Classes
I've come across this problem before and I was wondering what the standard solution is as it must be a common problem:
Imagine the following:
I have a document class called 'Tree'.
This class holds an array of apples (not the actual objects, just string codes as ID for each apple).
I have another class called 'Apple'. The Tree class creates objects of these Apples. Whenever an apple is created, the string ID of the apple is added to the array.
The problem is I need to access this array from my Apple class, although it only exists in the Tree class. I'd be able to pass the array to my Apple class, but I wouldn't be able to return it. How can I do this? How can I update the array in my document class (Tree) from the Apple class? I can't create an object of the Tree class from every single apple.
Is the answer to declare the array as static and then create objects of the document class? I can't see how I can update the array without creating an object of the class.
Thankyou for any help or information you can give.
Assigning Tween Classes To Objects In An Array
oh man this is heavy
My array has a few objects that are revolving like on a carrousell...I want them to react on my mouseclick.
I cant seem to get this to work...
how would one make objects in an array do things?
I cant even define the path to them properly, it appears that I SUCK.
Allow me to present to you my little code-turdthat wont work in a million years
_level0.holder_mc.dot0.onRelease = function() {
var xScaleT:Tween = new Tween(dot0, "_rotation", back.easeOut, 0, 1222, 2, true);
};
Id hugely appreciate some help...
Custom Classes: One Class Tracks Multiple Other Classes?
I'm working on a coloring that allows kids to place objects on a scene and then color them so the image can be printed out. So assume you have sky background, the child can select a bird object, drag it into place and once they have it in place, color everything on the page (with a given palette of colors.)
So far it going great. However I want to track what objects have been added to the drawing on the fly. I have a potential solution using arrays but I'm thinking this is perfect opportunity to start using custom classes.
I'm thinking that I'd create a new instantiate a copy of the object class each time an object is added to the scene. However to track the objects added to the scene I'm thinking I'll also use an listing class to track them.
What I'm not sure about is the would the listing class simply contain an array of object identifiers? Any thoughts on the structure of the listing class?
I'm very new to oop as I've mainly been doing procedural programming up to this point but I'm eager to give this a shot.
Thanks!
Using Flex Classes In Classes Linked To Symbols
Hi all
I have a fla file where I link a symbol to an action script class. This action script classes references mx.collections.ArrayCollection; so when I attempt to publish the fla file, I get the error message:
1017: The definition of base class ArrayCollection was not found.
I then tried to add a class path (this folder contains the mx... classes):
C:Program FilesAdobeFlex Builder 3sdks3.0.0frameworksprojectsframeworksrc
and the the above error 1017 wasresolved, but now I get the error:
Version.as, line 18 1004: Namespace was not found or is not a compile-time constant.
So now I am pretty much stuck. What do I need to do for this to work ? Please note that the code compiles fine in flex, so it is not som basic coding error ?
Instantiating Classes Inside Classes
I have a class called spaceship in which i have instanciated another class weapon. However, when i call on a method of weapon (which at this point is just simply trying to trace "hello"), it doenst work and the object basically doenst exist. It's delcared in the class as:
Code:
private var ShipWeapon:weapon;
Note that when I instantiate a weapon class on the main timeline the thing works and "hello" is printed to the output panel. However, nothing at all happens when instantiated the weapon class inside my spaceship class. Both traces come up "undefined". Do i need to declare the class as some sore of special class or somethings? Thanks in advance
[classes] Best Method To Communicate Between Classes
Here's the scenerio:
I have a component that is associated with a class. Inside the component is an empty movieclip.
-component (part of a class)
-mc
The main component's class upon init will load a movie from a remote server into the mc movieclip. System.security.allowDomain is in there...
Now, inside the swf that gets loaded into the mc is an empty movieclip that's associated with it's own class:
-component (part of a class)
-mc (contains loaded movie)
-mc (part of a separate class)
Now here's the challenge... I need to have the loaded movie > mc's class be able to communicate with the main component's class.
What's the best setup to be able to communicate between the two classes directly? That is, if I don't have loaded movie > mc > class inherit from the component's class.
thanks in advance...
Nathan
Best Flash Classes (Taught Classes)
I think this site is great for newbies in the flash world to Advanced flash developers. I am an intermediate flash designer/developer and I have been using flash since 1998. My strengths are more on the design side for sure. I am just curious what your experience is with going to a week long flash class. I have been to several classes and my last one was a week long one with Joshua Davis on advanced actionscript in NYC a while back. This was still coding in AS1 with dot syntax so only some of it is relevant to what we are doing today. I am wondering what are the best classes out there today and what your experiences are if you have been to any. I wish another event like this: grant skinners FITC flash 8 workshop or this Colin Moocks actionscript bootcamp were available but I can't find anything like it. My friend went to Colin's workshop a while back and mentioned how he went into design patterns with AS2 and it would be great to learn about that. ANyhow any suggestions would be great. Post your thoughts.
Instantiating Classes Inside Classes
I have a class called spaceship in which i have instanciated another class weapon. However, when i call on a method of weapon (which at this point is just simply trying to trace "hello"), it doenst work. The compiler obviously didn't flag anything, but i also get "undefined" for all my weapon class varibles. Do i need to declare the class as some sore of special class or somethings? Thanks in advance
Accessing Classes From Classes
ok something I don't get. In as2 I used to have a main class, which I created an instance of my Useful.as Class in. And then when I created say a monster instance from my monster class, I used to pass it a reference to the main class, so I could access the Useful instance from a function in my monster class like this
Code:
main.Useful.RandomNumber(1,100);
But this doesn't seem to work in as3
It just gives me a reference error, even though when you look with debug mode the Useful instance is sitting there in the main class, and there is also a reference inside my monster instance to the main class. I found that if a pass a direct reference to the Useful instance to the monsters constructor, and setup a var called Useful inside my monster instance then I can just do this
Code:
Useful.RandomNumber(1,100);
but why doesn't the old AS2 way of things work?
Accessing Classes From Other Classes
Two Classes: Tile, Map
I know Tile works and is accessible from the main timeline because I can create and object and trace properties, so the timeline is able to import it.
When placing the same import statement in the Map class I get: 1046: Type was not found or was not a compile-time constant: Tile.
Here is code
ActionScript Code:
package layout
{
public class Tile
{
public var filename:String;
public var myX:int;
public var myY:int;
public var ext:String;
public function Tile(sFilename:String)
{
filename = sFilename;
var nPos1 = sFilename.indexOf('_');
var nPos2 = sFilename.indexOf('.');
myX = Number(sFilename.substring(0, nPos1));
myY = Number(sFilename.substring(nPos1+1, nPos2));
ext = sFilename.substring(nPos2, sFilename.length);
}
}
}
ActionScript Code:
package layout
{
import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;
import layout.Tile;
public class Map extends Sprite
{
// tiles[y][x]
public var tiles:Array = new Array();
public function Map()
{
if (map == false)
{
var map:Sprite = new Sprite();
this.addChild(map);
}
}
public function AddTile(sFilename:String)
{
var Tile:Tile = new Tile(sFilename); //This line causes issue
tiles[Tile.myY] = new Array();
tiles[Tile.myY][Tile.myX] = new Array(Tile, false);
}
}
}
Using Classes Inside Of Classes
I have created a custom sound class called MySoundClass that extends the Sound class... it is declared as class com.stickyMatters.WineGlassPiano.MySoundClass. I also have another class called SongPlayer that is declared as com.stickyMatters.WineGlassPaino.SongPlayer... my question is.. how do i use the MySoundClass inside of the SongPlayer class... when I try to import it says I cannot use the import statement inside of a class file. I know in AS3 you can use the package keyword to create packages and do that... but as far as I can see there is no package keyword in AS2... because I tried, and it just tells me htere is a syntax error on the line with the package declaration... can you use one custom class inside another? and if so... how?
P.S. just to be sure... i am using flash CS3 and writing AS2 files. Thanks!
Classes In Mx 2004 (new To Classes)
hi everyone, Im Nubis, from Argentina.
Iīm new to woking whit classes, Im using flash mx 2004 pro.
Ive created a class, that works correctly, it creates a square, a textbox, and uses a variable to pupulate the textbox.
(im sorry for my english)
in my library i have a MC (an empty MC) that is linked to that class.
I use this script to place the clip on the stage
attachMovie("card", "card", 1)
iknow the class works fine, but, I dont know where to pass the parameters to the class.
And if I use : Card = new MyCard("this Cardīs Name or label ")
both the clip and the textbox are not created.
could anybody please help me?
thanks in advance :)
(feel free to make comments about my code)
this is my class code:
// MyCard
class MyCard extends MovieClip {
var thisCardName:String;
//method for creating the square
function gen_sqr (){
this.createEmptyMovieClip("Square",2);
with(this["Square"]){
beginFill (0x0099FF, 100);
lineStyle (1, 0x003399, 100);
moveTo (0, 0);
lineTo (100, 0);
lineTo (100, 70);
lineTo (0, 70);
lineTo (0, 0);
endFill();
}
}
//method for generating the textfield
function gen_txt(my_text){
this.createTextField("mytext",3,0,0,50,20);
with(this["mytext"]){
text = my_text;
multiline = true;
html = true;
}
}
//constructor
function MyCard (thisName:String){
//set the name or label for the card
thisCardName = thisName;
//
gen_sqr()
gen_txt(thisName)
//
trace("newclass Created")
trace(thisCardName)
}
}
Importing Classes In To AS3 Classes?
I am not sure how to import multiple classes into an AS3 class. Also I am bit confused on how "package" works now.
This is currently what I have and its wrong:
Code:
package {
import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;
class LoadImage {
public function LoadImage() {
var container:Sprite = new Sprite();
addChild(container);
var pictLdr:Loader = new Loader();
var pictURL:String = "catfishSMv.jpg"
var pictURLReq:URLRequest = new URLRequest(pictURL);
pictLdr.load(pictURLReq);
pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
function imgLoaded(e:Event):void {
container.addChild(pictLdr.content);
}
}
}
}
How should I actually do this?
Thanks
Classes In Mx 2004 (new To Classes)
hi everyone, Im Nubis, from Argentina.
Iīm new to woking whit classes, Im using flash mx 2004 pro.
Ive created a class, that works correctly, it creates a square, a textbox, and uses a variable to pupulate the textbox.
(im sorry for my english)
in my library i have a MC (an empty MC) that is linked to that class.
I use this script to place the clip on the stage
attachMovie("card", "card", 1)
iknow the class works fine, but, I dont know where to pass the parameters to the class.
And if I use : Card = new MyCard("this Cardīs Name or label ")
both the clip and the textbox are not created.
could anybody please help me?
thanks in advance :)
(feel free to make comments about my code)
this is my class code:
// MyCard
class MyCard extends MovieClip {
var thisCardName:String;
//method for creating the square
function gen_sqr (){
this.createEmptyMovieClip("Square",2);
with(this["Square"]){
beginFill (0x0099FF, 100);
lineStyle (1, 0x003399, 100);
moveTo (0, 0);
lineTo (100, 0);
lineTo (100, 70);
lineTo (0, 70);
lineTo (0, 0);
endFill();
}
}
//method for generating the textfield
function gen_txt(my_text){
this.createTextField("mytext",3,0,0,50,20);
with(this["mytext"]){
text = my_text;
multiline = true;
html = true;
}
}
//constructor
function MyCard (thisName:String){
//set the name or label for the card
thisCardName = thisName;
//
gen_sqr()
gen_txt(thisName)
//
trace("newclass Created")
trace(thisCardName)
}
}
Accessing Classes From Classes
Hi... I'm having some trouble with these bits of code... I got some help before from wangbar to sort it out when the var stored was in a class of its own. But trying to access it from another class isn't working...
class Ipa{
var c : Settings;
function Ipa() {
}
}
class Settings {
var currSubs:Boolean;
function Settings (s:Boolean) {
currSubs = s;
}
function getSubsOn ():Boolean {
return currSubs;
}
function setSubsOn (s:Boolean):Boolean {
currSubs = s;
return currSubs;
}
}
then at root level:
var dpp : Ipa = new Ipa();
dpp.c.setSubtitlesOn(false);
and level 3:
_global.subtitles = _level0.dpp.c.getSubtitlesOn();
if ( _global.subtitles == false){
_level3.speech._visible = false;
};
And nothing happens...subtitles still showing...
Thanks in advance for help.
silverswim
AS1 Classes And AS2 Intrinsic Classes
Anyone ever mess around with writing an AS1 style class (so that it can be used prior to your class export frame) and writing an intrinsic AS2 class to go along with it, to enable compile-time checking?
It's working well, at least for instance members. (The trick is you need to define your constructor like so:Code:
var MyAS1Class = function... and NOTCode:
function MyAS1Class...)
But for static members, I can't seem to get the compiler to recognize the AS1 static members as validating against the AS2 intrinsic classes static members. In other words:
Code:
import the.intrinsic.class.Foo
#include "the/actual/as1/class/Foo.as"
var myFoo:Foo = new Foo();
// This cause the compiler to complain:
myFoo.nonExistentProperty = "moo";
// This goes by undetected:
Foo.NON_EXISTENT_STATIC_PROP = "moo";
// This gets caught:
the.intrinsic.class.Foo.NON_EXISTENT_STATIC_PROP = "moo";
// But doesn't help because it's referencing the intrinsic class, which
// doesn't actually have any code and never gets compiled
(obviously the properties mentioned are not defined in this example intrinsic class)
It's apparently a problem of the actual AS1 class being a var on the timeline and the AS2 intrinsic class existing in a different namespace.
I've tried putting my AS1 class in the _global.the.intrinsic.class.Foo variable, like it would if it were a regular AS2 class.
I've tried Object.registerClass("_global.the.intrinsic.class.Foo", Foo), which I thought would work, but maybe I'm doing it wrong.
So far the best workaround is this:
Code:
Foo.__resolve = function(name:String):Void {
trace("Oops, the member you've accessed, " + name + ", does not exist");
}Which at least provides run-time checking, but not compile-time checking, which is obviously why I'm doing this intrinsic thing at all.
I know this is a very esoteric question...any suggestions?
PS
Man, I do NOT miss writing AS1 OOP! I tend to forget how great AS2 OOP is when I use it exclusively. But coming back to AS1 OOP...<napoleonDynamite>Gawh!</napoleonDynamite>
Array, Array HELP - Importing A External File Into N ARRAY - Almost There
I am reading and external file with the following code:
ActionScript Code:
on (release, keyPress "<Enter>") {
lv = new LoadVars();
lv.onLoad = function() {
questions1 = this.filelist0.split(",");
answers1 = this.filelist1.split(",");
for(i=0;i<questions1.length;i++)
//trace(questions1[i]+" "+answers1[i]);
trace(questions1[i]);
//assumes same number of scores in each list
};
lv.load("questions.txt");
}
When I parse the file it puts it into an columar format as it should...however I need it to look like this:
questions1=new Array ("2+4=?","What is the capital of Illinois?","What color is the sky?","10x(5+2)=?");
answers1=new Array ("8","springfield","blue","70");
How do I do that?
Text file look like this:
&questions1=2+4=?,What is the Capital of Illinois?,What color is the sky?,10x(5+2)=?")&
&answers1=8,springfield,blue,70&
Using Custom Classes Inside Of Custom Classes
I have created a custom sound class called MySoundClass that extends the Sound class... it is declared as class com.stickyMatters.WineGlassPiano.MySoundClass. I also have another class called SongPlayer that is declared as com.stickyMatters.WineGlassPaino.SongPlayer... my question is.. how do i use the MySoundClass inside of the SongPlayer class... when I try to import it says I cannot use the import statement inside of a class file. I know in AS3 you can use the package keyword to create packages and do that... but as far as I can see there is no package keyword in AS2... because I tried, and it just tells me htere is a syntax error on the line with the package declaration... can you use one custom class inside another? and if so... how?
P.S. just to be sure... i am using flash CS3 and writing AS2 files. Thanks!
Using Custom Classes Inside Of Custom Classes
I have created a custom sound class called MySoundClass that extends the Sound class... it is declared as class com.stickyMatters.WineGlassPiano.MySoundClass. I also have another class called SongPlayer that is declared as com.stickyMatters.WineGlassPaino.SongPlayer... my question is.. how do i use the MySoundClass inside of the SongPlayer class... when I try to import it says I cannot use the import statement inside of a class file. I know in AS3 you can use the package keyword to create packages and do that... but as far as I can see there is no package keyword in AS2... because I tried, and it just tells me htere is a syntax error on the line with the package declaration... can you use one custom class inside another? and if so... how?
P.S. just to be sure... i am using flash CS3 and writing AS2 files. Thanks!
Pls Help: Need To Create New Array Taking 3 Random Entries From An Existing Array
Hello
I have a 2d array:
qTeeth[1] = [How many teeth do we have?, 1-10, 11-20, 21-30, 11-20]
etc.
It goes [question, option1, option2, option3, real answer]
I now just want to extract 3 or so of these entries and create a new array with them. Since I want to just use 3 or so questions randomly from a large array of questions.
Does anyone know a good tidy script to do this with??
Thanks in advance,
Ben.
Array Text Into Textfield And Creating New Line For Each Array Element
I have an array called dropTarg1 which stores dropped-in items.
I want to loop through this array and in a textfield, display each array item on a new line of this text field
I think I need to use something like Array.join("/n") but I can't get it working properly. I hope that the /n would create a new line of the text field called reviewBoxContentText.
for(var i:Number = 0; i<dropTarg.length; i++){
with(reviewBoxContent.reviewBoxContentText){
autoSize = true;
text = dropTarg1.join("/n");
}
}
All that is happening though is that the text field displays on a single line with /n in between each array element.
Calling A Function With An Array Variable As Arguments Is Resetting Array?
I'm going to post the full code of the two functions, disregard the "fluff" unrelated to the two functions as it is all working flawless, I've tested this HEAVILY and cannot understand why it keeps setting the entire array to undefined!
Any help would be grateful.
ActionScript Code:
// processReplace Function function processReplace(transferFiles) { var processArray:Array = transferFiles.slice(); var fileName:String = new String(); var filesArray:Array = new Array(); var replaceArray:Array = new Array(); var exists:String = new String(); var error:String = new String(); var promptResult:String = new String(); // Check for (i=0; i<processArray.length; i++) { // This is where it bugs up <b>exists = processSearch(transferFiles[i][1]);</b> if (exists == "replace") { replaceArray.push(processArray[i]); } else { filesArray.push(processArray[i]); } } // Prompt if (replaceArray.length>0) { error = "Replace "+replaceArray.length+" item(s):
"; for (i=0; i<replaceArray.length; i++) { error += " - "+replaceArray[i][1]+"
"; } promptResult = mSystem.messageBox(error, "Replace Existing Files?", 4); } // Action if (promptResult == "NO") { transferFiles = filesArray; } else if (promptResult == "YES") { transferFiles = filesArray.concat(replaceArray); } processTransfer(transferFiles); }
The processSearch
ActionScript Code:
// == processSearch Function function processSearch(sentInfo) { for (i=0; i<_global.boxFiles.length; i++) { if (_global.boxFiles[i] == sentInfo[1]) { return "replace"; break; } } }
Basically it's supposed to check to see if the file exists and return as true if it does and add it to a replace array, then the replace array is processed into a single string and put into a dialog box through the flash wrapper prompting them to "replace the files or not".
It makes the replace array just fine, it actually even has the right "count" in it but it's setting all the "filenames" to undefined because of the exists = processSearch function.
I even tried to make a new array and run the search just from that one and set the values from the old one and it's still failing.
Is it because of the "break" or can anyone figure it out? Iknow it's hard because you can't use the code
ANY Solution ideas are welcome, even if you think it's dumb
Thanks!
Array.splice Works But Array.slice Doesnt?
This should be simple enough. I have an array of objects, and I want to SLICE a piece of the array and assign it to a new array. All of my attempts have failed. SPLICE works, and I could duplicate my original array into a temp array and splice out what I want, but surely slice is supposed to save me this trouble, right?
I'm a bit baffled, but here's the code:
Code:
private function createGlist() {
var glistObj:Glist = this;
xml_object = new XML();
xml_object.ignoreWhite = true;
xml_object.onLoad = function(success:Boolean):Void {
if(success) {
var i:Number = 0;
for (var this_node = this.firstChild.firstChild; this_node != null; this_node = this_node.nextSibling) {
glistObj.thumb_array.push(new Gthumb(glistObj, glistObj.thumb_array_mc.getNextHighestDepth(), this.firstChild.childNodes[i]));
i++;
}
var load_start:Number = 2;
var load_count:Number = 2;
glistObj.thumb_load_array = glistObj.thumb_array.slice(load_start,load_count);
trace(glistObj.thumb_load_array); //no result, no error
trace(glistObj.thumb_array.slice(load_start,load_count)); //no result, no error
trace(glistObj.thumb_array.splice(load_start,load_count)); //outputs [object Object],[object Object]
} else {
//error
}
}
xml_object.load(xml_url);
}
Array Copy Points To Original Array Instead Of Duplicating
Hey all.
Spent a long time trying to figure out what was wrong with my code. Then I remembered about arrays being objects instead of primitive variables. My question is, how can I make a duplicate copy of an Array?
Details:
So this code
PHP Code:
package{
import flash.display.*
public class tester extends MovieClip{
var a:Array = [1,2]
public function tester () {
var b = a
trace (a)
b.splice(1,1)
trace (a)
}
}
}
results in this output:
PHP Code:
1,2
1
How can i make b an actual duplicate of a, instead of a pointer?
PHP Code:
b = new Array
b = a
doesn't work either.
Thanks!
DHP
Creating Multi-dimentional Array From Single Array
I have an array
myArray=[hello,bye,fred,1,2,3,4,5,6];
I need to convert it to a multi-dimentional array that would look something like below
array1=[hello,bye,fred];
array2=[1,2,3];
array3=[4,5,6];
newArray=[array1, array2,array3];
I am not sure how to split the array can anyone help? myArray.length/3 would give me the number in each of the new arrays but I am puzzled after this?
Associating Array Elements With Another Array Keeping The Order.
hi, i have already posted this problem yesterday but i haven't solved it yet.
i have two arrays:
array_1[a,b,c,d]
array_2[01,02,03,04]
the first array represents mcs in my stage - the buttons of the menu.
the second represents other mcs, containing some text.
when i rollOver each element of array_1 i would like to show each element of array_2 in the same order and hide it when i rollOver another menu button to show a new one.
I mean, it always has to be showing a with 01, b with 02, c with 03...
any suggestions?
Array Of Movie Loaders/array Of Image Files
Alright. I'm fairly new to Actionscripting, so if we can somewhat lame out the tech talk to mild to medium I'd appreciate it. what I am trying to do is create an swf movie that will interact with a PHP script. first lets start with saying the PHP script reads the directory that it is currently in and filters out any file that is not a GIF,PNG, or JPG and then it suffes all of this into a URL encoded string and the directory path ,such as :
?pictures=image1+image2+image3+image4&path=http://servername/directoryPath
now i have flash load the variables "pictures" and split the images and stuff those into an array and the directory path of course stays in its own seperate variable. ive gotten this far with no problems.
so what im trying to do now with this info is create a bit of a slide show. I want to take the array of pictures and load those into an empty movie clip displaying each picture consecutively. Ive made several attempts but no such luck. Ive tried to use a for() loop to cycle through the array of pictures loading them into the empty clip. im still very new and rather lost with these objects and class use i. Im sure im probably not using a listener of somesort that i need and what not. I am sorry i am probably not giving enough info for all this. the whole idea of this clip is to be able to display an indefinite amount pictures , so the flash player will not know ahead of time how many pictures till the php script has sent all the names of what is in the directory. this movie needs to be able to dynamically load any images that are in that directory.so any suggestions on what i can do with an array an an empty clip? thank you to anyone who can make suggesions.
How Do I Lope Through Array, Delete Clip And Remove From Array
I have a function that creates an instance of a movieClip and adds it to an array.
In my gameloop I loop through the array and change some values. Now I want a cleanup function that loops through the array, and if the y value exceeds a certain value, I want to delete the clip instance and remove the record in the Array.
Could someone please help me with the syntax for that? I will lay the code out below.
Thankyou
Attach Code
var myClipArray = new Array();
public function createClipInstance() {
var myClipInstance:myClip = new myClip();
myClipInstance.y = 0;
addChild( myClipInstance );
myClipArray.push(myClipInstance);
}
// loop through array and check y value
// if y > 400: Delete clip and remove from array
public function cleanClips() {
for (var n:int = 0; n<myClipArray.length; n++){
if (myClipArray[n].y > 400) {
// DELETE CLIP AND REMOVE FROM ARRAY
trace("this is where I need help");
}
}
}
Generate Random Value From Array 'excluding' The Current Array Value
getting my head round flash (sorta!)...
ok, nearly got this working; i have 11 movie clips on the root timeline and a empty controller movie. what i need to happen is for a random movie clip to play. when it reaches a point in it's own timeline, it sets the playNext variable to true and the controller movie clip works out the next random movie to play.
the problem comes when the controller 'randomly' picks the movie clip thats already playing! then the whole thing breaks...
is there a way that i can say 'generate me a random clip to play from this array 'excluding' the currently playing movie clip'?
any suggestions would be grand.
this is what i have on my controller clip:
onClipEvent (load) {
//define a new array
video_array = new Array();
//list each of the videos
video_array[0] = "zero";
video_array[1] = "one";
video_array[2] = "two";
video_array[3] = "three";
video_array[4] = "four";
video_array[5] = "five";
video_array[6] = "six";
video_array[7] = "seven";
video_array[8] = "eight";
video_array[9] = "nine";
video_array[10] = "ten";
//this is the count of how many elements (videos) are in your array
max = video_array.length;
//set the playNext to true
_root.playNext = true;
}
onClipEvent (enterFrame) {
//if playNext is true
if (_root.playNext) {
//generate a new random video to play
randomNumber = Math.floor(Math.random()*max);
//store the name
randomVideo = video_array[randomNumber];
//tell that video to play
_parent[randomVideo].gotoAndPlay(13);
//record the video we are playing
crntVideo = randomVideo;
//set playNext to false
_root.playNext = false;
}
}
Load Xml Images-->Array-->Duplicate Array: AHAA
Hello Kirupians!
[Summary]
I want to load images from an XML, then store the images inside an array, then duplicate that array into other clone arrays so that I can addChild() copies of the images into stage whenever i want (and be able to change their properties).
Basicly i have to create two duplicates; big_img and icon_image
[SYMPTOMS]
Everything is loaded fine;the big_imgloads and positions correctly, but, when i try to load icon_image the first big_img disappears! as if the new array has hasn't duplicated the original array (as if it's only a shortcut, not a real copy).
The cody thing:
ActionScript Code:
// total images read from XMLvar axiLength=Accessoir.length();// main image container arrayvar axxARR:Array = new Array();// add images to arrayfor (var k=0; k<axiLength; k++) { var axxLoader:Loader = new Loader(); axxLoader.load(new URLRequest(Accessoir.PHOTO.text()[k])); axxARR.push(axxLoader); axxLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, axxLoaded);}function axxLoaded(e:Event):void { // show big image if (axiLength==axxARR.length) { axxShow(0); }}function axxShow(ID_AXX:Number) { // duplicate images array var axxImage:Array=axxARR.concat(axxARR); // reposition it axxImage[ID_AXX].x = product_details_swf.axx.x+(axxImage[ID_AXX].width/2)-5.5; // Add init image to accessoires axxImage[ID_AXX].name="axxImage"; product_details_swf.axx.addChild(axxImage[ID_AXX]);}// here i got an event listner to a button, once rolle over is triged it // should make small copies of the whole array images and put them on stage//....function rollover_button(ID_AXX:Number) { for (var i=0; i<axiLength; i++) { axxCreate(i); } function axxCreate(ID_AXX:Number) { var axxPic:Array=axxARR.concat(); imageResizer(axxPic[ID_AXX], 50, 50); axxPic[ID_AXX].name="axxPic_"+ID_AXX; axxPic[ID_AXX].x=product_details_swf.axx.getChildByName("axxBG_"+ID_AXX).x+axxPicSpacingX; axxPic[ID_AXX].y=product_details_swf.axx.getChildByName("axxBG_"+ID_AXX).y+axxPicSpacingY; product_details_swf.axx.addChild(axxPic[ID_AXX]); }}
[MORE INFORMATION]
I tried array duplication using; concat and slice but not work, it doesn't creat copies of the orriginal array, but just a shortcut to it!
thanx for any tips!
Generate Random Value From Array 'excluding' The Current Array Value
getting my head round flash (sorta!)...
ok, nearly got this working; i have 11 movie clips on the root timeline and a empty controller movie. what i need to happen is for a random movie clip to play. when it reaches a point in it's own timeline, it sets the playNext variable to true and the controller movie clip works out the next random movie to play.
the problem comes when the controller 'randomly' picks the movie clip thats already playing! then the whole thing breaks...
is there a way that i can say 'generate me a random clip to play from this array 'excluding' the currently playing movie clip'?
any suggestions would be grand.
this is what i have on my controller clip:
onClipEvent (load) {
//define a new array
video_array = new Array();
//list each of the videos
video_array[0] = "zero";
video_array[1] = "one";
video_array[2] = "two";
video_array[3] = "three";
video_array[4] = "four";
video_array[5] = "five";
video_array[6] = "six";
video_array[7] = "seven";
video_array[8] = "eight";
video_array[9] = "nine";
video_array[10] = "ten";
//this is the count of how many elements (videos) are in your array
max = video_array.length;
//set the playNext to true
_root.playNext = true;
}
onClipEvent (enterFrame) {
//if playNext is true
if (_root.playNext) {
//generate a new random video to play
randomNumber = Math.floor(Math.random()*max);
//store the name
randomVideo = video_array[randomNumber];
//tell that video to play
_parent[randomVideo].gotoAndPlay(13);
//record the video we are playing
crntVideo = randomVideo;
//set playNext to false
_root.playNext = false;
}
}
Copying Loaded Array Into A Local Array
I'm loading an array through loadVariablesNum (into level 0). The script properly returns array values... I've checked by using text boxes on my stage. But, when I try to store the loaded array within a local Actionscript array for manipulation, it doesn't seem to be able to read the loaded values. It's as if the stage and the frame Actionscript were independent of each other. Can anyone help?
Thanks
Inserting An Array Into An Array To Make It Multidemensional
hi there,
Using an ASP script I've managed to get strings into flash
at the moment the strings come in like this:
array1=data1,data2,data3,data4,data5
array2=celeb1,celeb2,celeb3,celeb4,celeb5
currently I'm doing this:
webfoldercontents = new Array();
webfoldercontens = websubfolders.split(",");
which creats a 2d array. what I need is this:
multidemesionalarray = [array1[array2]]
any help v.appreciated!
Danny
Saving An Array Then Importing Saved Array?
I am creating a kids activity. At the moment I am working on the stamp tool that allws them to stamp a shape in different colours over the canvas... this is working fine, however I need to track the position and colour (and maybe more later) so that the child can save the activity and go back to it later.
So far I have managed to create an array for each propery (_x position, _y position and colour) in seperate arrays as a new stamp is attached it is given a number (1,2,3,4...) and in each array entry of that number are the position or colour properties. When I save these arrays (using FSCommand in Flash5) I think thay form a string in the text document.
When I loads the array from the text document, that looks like this:
&colourArray=255,255,255,16711680,16711680,1671168 0,16711680,16711680,16711680,16711680&XposArray=23 3,420.95,389,262,556.95,674.95,619.95,481.95,458.9 5,280&YposArray=109,167,313,211,301,158,80,105,174 ,451.95
I cannot pull out the data from the arrays (colourArray[2] traces as undefined) What I want to do is a loop based on the lenght of one the arrays that attaches the stamp MC in the correct position and colour.
Hope someone can shed light on this for me... I think I need to find a way to convert the text file data from a string to an array?!?
Cheers
Oll
|