Troubling Problem With Objects Arrays And XML
Could someone please help me out. I've allready spent 48 hours on this!!! I have a code: Code: stop();aantalSets = 4;aantalVragen = 4;aantalAntwoorden = 5;qq = new Object();qq.kleur = new Array();for (var aa = 0; aa<aantalSets; aa++) { qq.kleur[aa] = new Object(); qq.kleur[aa].naam = new String(); qq.kleur[aa].titeltekst = new String(); qq.kleur[aa].vragen = new Array(); for (var bb = 0; bb<aantalVragen; bb++) { qq.kleur[aa].vragen[bb] = new Object(); qq.kleur[aa].vragen[bb].vraagtekst = new String(); qq.kleur[aa].vragen[bb].beantwoord = new String(); qq.kleur[aa].vragen[bb].antwoorden = new Object(); qq.kleur[aa].vragen[bb].antwoorden.antwoordtekst = new Array(); qq.kleur[aa].vragen[bb].antwoorden.antwoordwaarde = new Array(); for (var cc = 0; cc<aantalAntwoorden; cc++) { qq.kleur[aa].vragen[bb].antwoorden.antwoordtekst[cc] = new String(); qq.kleur[aa].vragen[bb].antwoorden.antwoordwaarde[cc] = new String(); } }} // this was used as sample data but should come from the XML fileqq.kleur[0].naam = "rood";qq.kleur[0].titeltekst = "Rood en bla bla";qq.kleur[0].vragen[0].vraagtekst = "Dit is vraag 1 van rood";qq.kleur[0].vragen[0].beantwoord = "1";// waarde van vraag 1 antwoord 2 fictiefqq.kleur[0].vragen[0].antwoorden.antwoordtekst[0] = "Dit is antwoord 1";qq.kleur[0].vragen[0].antwoorden.antwoordtekst[1] = "Dit is antwoord 2";qq.kleur[0].vragen[0].antwoorden.antwoordtekst[2] = "Dit is antwoord 3";qq.kleur[0].vragen[0].antwoorden.antwoordtekst[3] = "Dit is antwoord 4";qq.kleur[0].vragen[0].antwoorden.antwoordtekst[4] = "Dit is antwoord 5";qq.kleur[0].vragen[0].antwoorden.antwoordwaarde[0] = "6";qq.kleur[0].vragen[0].antwoorden.antwoordwaarde[1] = "1";qq.kleur[0].vragen[0].antwoorden.antwoordwaarde[2] = "4";qq.kleur[0].vragen[0].antwoorden.antwoordwaarde[3] = "2";qq.kleur[0].vragen[0].antwoorden.antwoordwaarde[4] = "3";qq.kleur[0].vragen[1].vraagtekst = "Dit is vraag 2 van rood";qq.kleur[0].vragen[1].beantwoord = "6";// waarde van vraag 2 antwoord 1 fictiefqq.kleur[0].vragen[1].antwoorden.antwoordtekst[0] = "Dit is antwoord 1";qq.kleur[0].vragen[1].antwoorden.antwoordtekst[1] = "Dit is antwoord 2";qq.kleur[0].vragen[1].antwoorden.antwoordtekst[2] = "Dit is antwoord 3";qq.kleur[0].vragen[1].antwoorden.antwoordtekst[3] = "Dit is antwoord 4";qq.kleur[0].vragen[1].antwoorden.antwoordtekst[4] = "Dit is antwoord 5";qq.kleur[0].vragen[1].antwoorden.antwoordwaarde[0] = "6";qq.kleur[0].vragen[1].antwoorden.antwoordwaarde[1] = "1";qq.kleur[0].vragen[1].antwoorden.antwoordwaarde[2] = "4";qq.kleur[0].vragen[1].antwoorden.antwoordwaarde[3] = "2";qq.kleur[0].vragen[1].antwoorden.antwoordwaarde[4] = "3";for (var aa = 0; aa<aantalSets; aa++) { trace(qq.kleur[aa].naam); trace(qq.kleur[aa].titeltekst); for (var bb = 0; bb<aantalVragen; bb++) { trace(qq.kleur[aa].vragen[bb].vraagtekst); trace(qq.kleur[aa].vragen[bb].beantwoord); for (var cc = 0; cc<aantalAntwoorden; cc++) { trace(qq.kleur[aa].vragen[bb].antwoorden.antwoordtekst[cc]); trace(qq.kleur[aa].vragen[bb].antwoorden.antwoordwaarde[cc]); } }} And to make this readable from an XML file, HOW DO I DO THIS!!! I looked at several parsing methods but I keep getting stuck. The XML looks like this (or should it, i made it up myself)??? Code: <?xml version="1.0" encoding="utf-8"?><scan> <vragenset naam="rood" titeltekst="Rood en bla bla"> <vraag vraagtekst="Dit is vraag 1 van rood"> <antwoordtekst value="6">Dit is antwoord 1</antwoordtekst> <antwoordtekst value="1">Dit is antwoord 2</antwoordtekst> <antwoordtekst value="4">Dit is antwoord 3</antwoordtekst> <antwoordtekst value="2">Dit is antwoord 4</antwoordtekst> <antwoordtekst value="3">Dit is antwoord 5</antwoordtekst> </vraag> <vraag vraagtekst="Dit is vraag 2 van rood"> <antwoordtekst value="6">Dit is antwoord 1</antwoordtekst> <antwoordtekst value="1">Dit is antwoord 2</antwoordtekst> <antwoordtekst value="4">Dit is antwoord 3</antwoordtekst> <antwoordtekst value="2">Dit is antwoord 4</antwoordtekst> <antwoordtekst value="3">Dit is antwoord 5</antwoordtekst> </vraag> <vraag vraagtekst="Dit is vraag 3 van rood"> <antwoordtekst value="6">Dit is antwoord 1</antwoordtekst> <antwoordtekst value="1">Dit is antwoord 2</antwoordtekst> <antwoordtekst value="4">Dit is antwoord 3</antwoordtekst> <antwoordtekst value="2">Dit is antwoord 4</antwoordtekst> <antwoordtekst value="3">Dit is antwoord 5</antwoordtekst> </vraag> <vraag vraagtekst="Dit is vraag 4 van rood"> <antwoordtekst value="6">Dit is antwoord 1</antwoordtekst> <antwoordtekst value="1">Dit is antwoord 2</antwoordtekst> <antwoordtekst value="4">Dit is antwoord 3</antwoordtekst> <antwoordtekst value="2">Dit is antwoord 4</antwoordtekst> <antwoordtekst value="3">Dit is antwoord 5</antwoordtekst> </vraag> </vragenset> <vragenset naam="blauw" titeltekst="Blauw en bla bla"> <vraag vraagtekst="Dit is vraag 1 van blauw"> <antwoordtekst value="6">Dit is antwoord 1</antwoordtekst> <antwoordtekst value="1">Dit is antwoord 2</antwoordtekst> <antwoordtekst value="4">Dit is antwoord 3</antwoordtekst> <antwoordtekst value="2">Dit is antwoord 4</antwoordtekst> <antwoordtekst value="3">Dit is antwoord 5</antwoordtekst> </vraag> <vraag vraagtekst="Dit is vraag 2 van blauw"> <antwoordtekst value="6">Dit is antwoord 1</antwoordtekst> <antwoordtekst value="1">Dit is antwoord 2</antwoordtekst> <antwoordtekst value="4">Dit is antwoord 3</antwoordtekst> <antwoordtekst value="2">Dit is antwoord 4</antwoordtekst> <antwoordtekst value="3">Dit is antwoord 5</antwoordtekst> </vraag> <vraag vraagtekst="Dit is vraag 3 van blauw"> <antwoordtekst value="6">Dit is antwoord 1</antwoordtekst> <antwoordtekst value="1">Dit is antwoord 2</antwoordtekst> <antwoordtekst value="4">Dit is antwoord 3</antwoordtekst> <antwoordtekst value="2">Dit is antwoord 4</antwoordtekst> <antwoordtekst value="3">Dit is antwoord 5</antwoordtekst> </vraag> <vraag vraagtekst="Dit is vraag 4 van blauw"> <antwoordtekst value="6">Dit is antwoord 1</antwoordtekst> <antwoordtekst value="1">Dit is antwoord 2</antwoordtekst> <antwoordtekst value="4">Dit is antwoord 3</antwoordtekst> <antwoordtekst value="2">Dit is antwoord 4</antwoordtekst> <antwoordtekst value="3">Dit is antwoord 5</antwoordtekst> </vraag> </vragenset></scan> Please please help me out!!! Greetz TayFF
KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 11-19-2008, 07:06 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Troubling With Checkboxes
I am creating a map and I have 2 checkboxes so far
checkbox1: shows the land when checked
checkbox2: shows the border between the countries
after adding checkbox2 into the same layer and frame as checkbox1, only one checkbox appears when I tested the movie which is checkbox2. how do I am make both checkboxes appear
what i have tried is changing the all the fcheck to gcheck in checkbox2 and left checkbox 1 alone but the only different that happen when i check marked the map it doesnt show the border and instead shows the land in checkbox 1
they both under the same fuicomponents
thanks
Checkbox1:
and the only thing different in checkbox2 is instead having land in the script it has the word borders
this.setValue(!( this.checked ));
if (this.checked)
{
_root.borders.nextFrame();
}
else
{
_root.borders.prevFrame();
}
}
------------------------------------------------------------
#initclip 1
function FCheckBoxClass()
{
this.init();
}
FCheckBoxClass.prototype = new FUIComponentClass();
Object.registerClass("FCheckBoxSymbol", FCheckBoxClass);
FCheckBoxClass.prototype.init = function()
{
super.setSize(this._width,this._height);
this.boundingBox_mc.unloadMovie();
this.attachMovie("fcb_hitArea","fcb_hitArea_mc",1) ;
this.attachMovie("fcb_states", "fcb_states_mc",2);
this.attachMovie("FLabelSymbol","fLabel_mc",3);
super.init();
this.setChangeHandler(this.changeHandler);
this._xscale = 100;
this._yscale = 100;
this.setSize(this.width,this.height);
if ( this.initialValue == undefined ) {
this.setCheckState(false);
} else {
this.setCheckState(this.initialValue);
}
if(this.label != undefined){
this.setLabel(this.label);
}
// ACCESSIBILITY DEFINED :: _accImpl object defined in base class
this.ROLE_SYSTEM_CHECKBUTTON = 0x2c;
this.STATE_SYSTEM_CHECKED = 0x10;
this.EVENT_OBJECT_STATECHANGE = 0x800a;
this.EVENT_OBJECT_NAMECHANGE = 0x800c;
this._accImpl.master = this;
this._accImpl.stub = false;
this._accImpl.get_accRole = this.get_accRole;
this._accImpl.get_accName = this.get_accName;
this._accImpl.get_accState = this.get_accState;
this._accImpl.get_accDefaultAction = this.get_accDefaultAction;
this._accImpl.accDoDefaultAction = this.accDoDefaultAction;
}
FCheckBoxClass.prototype.setLabelPlacement = function( pos )
{
this.setLabel(this.getLabel());
this.txtFormat( pos );
var halfLabelH = this.fLabel_mc._height/2;
var halfFrameH = this.fcb_states_mc._height/2;
var vertCenter = (halfFrameH - halfLabelH );
var checkWidth = this.fcb_states_mc._width;
var frame = this.fcb_states_mc
var label = this.fLabel_mc;
var w = 0;
if (frame._width > this.width){
w = 0;
} else {
w = this.width - frame._width;
}
this.fLabel_mc.setSize(w);
if (pos == "right" || pos == undefined){
this.labelPlacement = "right";
this.fcb_states_mc._x = 0;
this.fLabel_mc._x = checkWidth;
this.txtFormat("left");
} else if (pos == "left"){
this.labelPlacement = "left";
this.fLabel_mc._x = 0;
this.fcb_states_mc._x = this.width - checkWidth;
this.txtFormat("right");
}
this.fLabel_mc._y = vertCenter;
this.fcb_hitArea_mc._y = vertCenter;
}
FCheckBoxClass.prototype.txtFormat = function( pos )
{
var txtS = this.textStyle;
var sTbl = this.styleTable;
txtS.align = (sTbl.textAlign.value == undefined) ? txtS.align = pos : undefined;
txtS.leftMargin = (sTbl.textLeftMargin.value == undefined) ? txtS.leftMargin = 0 : undefined;
txtS.rightMargin = (sTbl.textRightMargin.value == undefined) ? txtS.rightMargin = 0 : undefined
if(this.flabel_mc._height > this.height){
super.setSize(this.width,this.flabel_mc._height);
}else{
super.setSize(this.width,this.height);
}
this.fLabel_mc.labelField.setTextFormat(this.textS tyle);
this.setEnabled(this.enable)
}
FCheckBoxClass.prototype.setHitArea = function(w,h)
{
var hit = this.fcb_hitArea_mc;
this.hitArea = hit;
if ( this.fcb_states_mc._width > w ){
hit._width = this.fcb_states_mc._width;
}else{
hit._width = w;
}
hit._visible = false;
if(arguments.length > 1){
hit._height = h;
}
}
FCheckBoxClass.prototype.setSize = function(w)
{
this.setLabel(this.getLabel());
this.setLabelPlacement(this.labelPlacement);
if(this.fcb_states_mc._height < this.flabel_mc.labelField._height){
super.setSize(w,this.flabel_mc.labelField._height) ;
}
this.setHitArea(this.width,this.height);
this.setLabelPlacement(this.labelPlacement);
}
FCheckBoxClass.prototype.drawFocusRect = function()
{
this.drawRect(-2, -2, this._width+6, this._height-1);
}
FCheckBoxClass.prototype.onPress = function()
{
this.pressFocus();
_root.focusRect.removeMovieClip();
var states = this.fcb_states_mc;
if (this.getValue()) {
states.gotoAndStop( "checkedPress" );
} else {
states.gotoAndStop( "press" );
}
}
FCheckBoxClass.prototype.onRelease = function()
{
this.fcb_states_mc.gotoAndStop( "up" );
this.setValue(!( this.checked ));
if (this.checked)
{
_root.land.nextFrame();
}
else
{
_root.land.prevFrame();
}
}
FCheckBoxClass.prototype.onReleaseOutside = function()
{
var states = this.fcb_states_mc;
if (this.getValue()) {
states.gotoAndStop( "checkedEnabled" );
} else {
states.gotoAndStop("up");
}
}
FCheckBoxClass.prototype.onDragOut = function()
{
var states = this.fcb_states_mc;
if (this.getValue()) {
states.gotoAndStop( "checkedEnabled" );
} else {
states.gotoAndStop("up");
}
}
FCheckBoxClass.prototype.onDragOver = function()
{
var states = this.fcb_states_mc;
if (this.getValue()) {
states.gotoAndStop( "checkedPress" );
} else {
states.gotoAndStop("press");
}
}
FCheckBoxClass.prototype.setValue = function( checkedValue )
{
if ( checkedValue || checkedValue == undefined) {
this.setCheckState( checkedValue );
} else if (checkedValue == false){
this.setCheckState( checkedValue );
}
this.executeCallBack();
if(Accessibility.isActive()){
Accessibility.sendEvent( this, 0, this.EVENT_OBJECT_STATECHANGE,true );
}
}
FCheckBoxClass.prototype.setCheckState = function( checkedValue )
{
var states = this.fcb_states_mc;
if ( this.enable ) {
this.flabel_mc.setEnabled(true);
if ( checkedValue || checkedValue == undefined) {
states.gotoAndStop( "checkedEnabled" );
this.enabled = true;
this.checked = true;
}
else
{
states.gotoAndStop("up");
this.enabled = true;
this.checked = false;
}
}
else
{
this.flabel_mc.setEnabled(false);
if ( checkedValue || checkedValue == undefined) {
states.gotoAndStop( "checkedDisabled" );
this.enabled = false;
this.checked = true;
}
else
{
states.gotoAndStop( "uncheckedDisabled" );
this.enabled = false;
this.checked = false;
this.focusRect.removeMovieClip()
}
}
}
FCheckBoxClass.prototype.getValue = function()
{
return (this.checked);
}
FCheckBoxClass.prototype.setEnabled = function( enable )
{
if(enable == true || enable == undefined){
this.enable = true;
Super.setEnabled(true);
} else {
this.enable = false;
Super.setEnabled(false);
}
this.setCheckState(this.checked);
}
FCheckBoxClass.prototype.getEnabled = function()
{
return(this.enable);
}
FCheckBoxClass.prototype.setLabel = function( label )
{
this.fLabel_mc.setLabel(label);
this.txtFormat();
// ACCESSIBILITY
if(Accessibility.isActive()){
Accessibility.sendEvent( this, 0, this.EVENT_OBJECT_NAMECHANGE );
}
}
FCheckBoxClass.prototype.getLabel = function()
{
return (this.fLabel_mc.labelField.text);
}
FCheckBoxClass.prototype.setTextColor = function( color )
{
this.fLabel_mc.labelField.textColor = color;
}
FCheckBoxClass.prototype.myOnKeyDown = function( )
{
if (Key.getCode() == Key.SPACE && this.pressOnce == undefined && this.enabled == true) {
this.setValue(!this.getValue());
this.pressOnce = true;
}
}
FCheckBoxClass.prototype.myOnKeyUp = function( )
{
if (Key.getCode() == Key.SPACE) {
this.pressOnce = undefined;
}
}
// START ACCESSIBILITY METHODS
FCheckBoxClass.prototype.get_accRole = function(childId)
{
return this.master.ROLE_SYSTEM_CHECKBUTTON;
}
FCheckBoxClass.prototype.get_accName = function(childId)
{
return this.master.getLabel();
}
FCheckBoxClass.prototype.get_accState = function(childId)
{
if (this.master.getValue()){
return this.master.STATE_SYSTEM_CHECKED;
}else{
return 0;
}
}
FCheckBoxClass.prototype.get_accDefaultAction = function(childId)
{
if ( this.master.getValue() ){
return "UnCheck";
}else{
return "Check";
}
}
FCheckBoxClass.prototype.accDoDefaultAction = function(childId)
{
this.master.setValue( !this.master.getValue() );
}
// END ACCESSIBILITY METHODS ::mr::
#endinitclip
boundingBox_mc._visible = false;
deadPreview._visible = false;
Page Change - Been Troubling Me For Ages Now
Hi hope someone can help!
Basically I have a transition which is a moving text box which slides in and then slides out.
I will need to make about 10 of these, and I know that rather than make a huge timeline and keep duplicating the frames and changing the text there is a way that I can just have one transition, and then the text inside a movie clip.
Each text movie clip frame will then have a stop action and a different bit of text for each frame.
All i need is to know the action script to put on the page before.
To sum it up I need the actionscript to perform this:
If movie restarted, MYTEXT.gotoAndStop.nextFrame
Something like that anyway lol. Someone please help me ;-) Thanks
Only Arrays Or Arrays And Objects
Hi
I've been told not to do this with an array...
PHP Code:
var travelbooks:Array = new Array();
travelbooks.push({titel: "Madrid", release: 2004, pages: 248});
travelbooks.push({titel: "Barcelona", release: 2003, pages: 224});
travelbooks.push({titel: "Tenerife", release: 2002, pages: 124});
travelbooks.push({titel: "Malaga", release: 2005, pages: 172});
for (var i=0; i < travelbooks.length; i++) {
trace(travelbooks[i].release + " - " + travelbooks[i].titel);
}
... but to do this...
PHP Code:
var travelbooks:Array = new Array();
var book_1:Object = {titel: "Madrid", release: 2004, pages: 248};
var book_2:Object = {titel: "Barcelona", release: 2003, pages: 224};
var book_3:Object = {titel: "Tenerife", release: 2002, pages: 124};
var book_4:Object = {titel: "Malaga", release: 2005, pages: 172};
travelbooks.push(book_1, book_2, book_3, book_4);
trace(book_1.titel);
trace(travelbooks);
trace(book_releases);
function book_releases():void {
for (var i:Number = 0; i < travelbooks.length; i++) {
trace(travelbooks[i].release + " - " + travelbooks[i].titel);
}
}
Could you tell me why i'm not supposed to use the first example? And why example 2 doesn't work?
Thank you
Ferran
Objects In Arrays
What is the syntax to place an object into an array?
I am using
jars = new Array();
jars[0] = _root["j_manning"];
where _root.j_manning is one of the objects I want to store in the array but it isn't working.
Please help!
Objects & Arrays
I am trying to modify a Flash movie that was written for me by someone else. The movie allows the user to drag elements for what is essentially a palette and drop them on to a floorplan. When the user is finished and submits the form, I need to pass to a CGI each object's x, y, and rotation. As a programmer, I would create an array of objects and loop through the array to pull the data I need. However, the person who wrote this used DuplicateMovieClip to create a new object. Can I tell Flash to put this new object at the end of an array? Or is there another way to duplicate the clip and push the resulting object to an array?
Objects Vs Arrays
I need to store a substantial chunk of data in an array with reference by unique string IDs. There will be anywhere between 200 and 2000 entries, and they will be stored by strings such as "DOG","CAT","PANDA","HORSE" and so on.
My question is what is the most efficient way of storing these so that it takes the least amount of time to find information in the arrays. Currently I'm considering either making it an object :
list = {DOG : new Animal(), CAT : new Animal(),
PANDA : new Animal(), HORSE : new Animal()};
or into an array:
list=[];
list["DOG"]=new Animal();
list["CAT"]=new Animal();
list["PANDA"]=new Animal();
list["HORSE"]=new Animal();
My instict tells me that the array is a simpler storage structure (perhaps because it automatically alphabatizes it), and that retrieving data from it will be faster, but I'm not positive. The array may also be simpler for me to code.
Beyond this, I also am considering breaking up the array or object into a table. There would be 8 arrays each holding 3-4 letters of the alphabet. I could check the reference first and then point it to the correct array. I'm not sure if there is an optimal way to do this though, or if it will in fact make my code any faster at all. I'd appreciate any insight you all have with Arrays vs Objects and how I can best code this.
Arrays Of Objects
Suppose I have an object declared like this:
var myVanityTop:vanity_top_object = new vanity_top_object();
How would I declare an array of 10 objects of type vanity_top_object()?
-Jay
(patel at cs dot utk dot edu)
Objects And Arrays
Hi as you can see fromt he actionscript below, I am trying to build an array/arrays of dynamically built objects. My thought is to fill an object with variables and then put that object and others that are the similar into an array. Then access the objects from the array to get the information out. It's not working. Could you please look at the mess of code I have written below and provide any feedback as to where I'm going wrong or alternative ways of accomplishing this task.
Thanks.
code: //Set Up Variables
var rootNode:XMLNode;
var courseTitle:String;
var i:Number = 0;
var myQuestionObject:Object = new Object(catagory, questionNum, dollarValue, answer, question);
var animalsArray:Array = new Array(); // This is the array to watch
var catagoryArray:Array = new Array();
//Load XML
var myXML:XML = new XML();
myXML.load("myTestCourse.xml");
myXML.ignoreWhite = true;
myXML.onLoad = function(success){
if(success){
rootNode = myXML.firstChild;
courseTitle = rootNode.firstChild.nodeValue;
//Create Question Arrays
for (var aNode:XMLNode = rootNode.firstChild.nextSibling; aNode != null; aNode=aNode.nextSibling) {
var objectName:String = "myQuestionObject" + i;
this[objectName] = new Object();
this[objectName].catagory = aNode.firstChild.firstChild.nodeValue;
this[objectName].dollarValue = aNode.firstChild.nextSibling.firstChild.nodeValue;
this[objectName].answer = aNode.firstChild.nextSibling.nextSibling.firstChil d.nodeValue;
this[objectName].question = aNode.firstChild.nextSibling.nextSibling.nextSibli ng.firstChild.nodeValue;
this[objectName].idNumber = i;
trace(this[objectName].catagory); // animalsif(this[objectName].catagory + "Array"){
trace("Found Array"); // It does find it.
this[this[objectName].catagory + "Array"].push(this[objectName]); //Put the object in the array
}else{
trace("Didin't Find Array");
//this[thisArray] = new Array();
//this[thisArray].push(this[objectName]);
}
trace(_root.animalsArray[0].question); //undefined
i++
}
}
}
_t
XML Into Objects Into Arrays
I keep thinking this problem should have a simple solution, but I can't seem to come up with it...
I've managed to write a function that puts all the XML from the input file into a series of heirarchical objects. Now, however, I want to put those objects into arrays -- I need an indexed-based method of accessing them as well as an associative one.
Or do I?
I have three basic levels of information: sections, topics, and slides. I want to push all the section objects into the sections array: each section level will have its own topics array (into which I want to push -- you guessed it! -- the relevant topic objects). And then teach topic level will have its own slides array...
A pseudo-example of what I hope to end up with is this:
sections[0]
........topics[0]
................slides[0]
........................text_1
........................text_2
........................bullets[0]
................................bullet_1
................................bullet_2
................slides[1]
........................text_1
........................text_2
........topics[1]
................slides[0]
........................text_1
ad nauseum, ad infinitum...
I would greatly appreciate any help anyone can provide! Thanks in advance!!!
If having the source files would help you understand just what the heck I'm talking about, I'd be happy to send them along!
Objects In Arrays
This is more a question whether this is a bug or if it's not, how I can work around it :-)
We have a class:
Code:
class Holder {
private var nr:Number
public Holder( nr:Number) {
this.nr = nr;
}
}
In the code where you make an object of this class, you cannot access the private member nr, so you'll get compiler errors if you do this:
Code:
var test:Holder = new Holder(1);
test.nr = 2;
But however, if you put your objects in an Array, you can access your private members like this:
Code:
var test:Array = new Array();
test.push( new Holder(1) );
test[0].nr = 2;
This won't give you compiler errors but it should imo, or am I missing something?
Objects And Arrays
For all you clever guys out there! I am making a shopping cart and I use objects to store information. like
var cart1 bject;
cart1.price=20.00;
cart1.description=kjkjdhfk;
cart1.picture="myfolder/url";
then i put this object into a cart array. so that whenever a add to cart button is pressed . the cart1 object is put into the cart array. You follow. How oh how do i get the properties out of the cart array. like cart1.price. I need thids info out of cart array?
Anyone.... someone???
[F8] Arrays And Objects
hi,
i'm having a slight problem regarding objects in arrays. i'm making an interactive body to fudle with. somwhere in my code, i make some objects and put these in an array:
PHP Code:
var heart_Organ:Object = new Organ(_root.body_mc.cardio_mc.heart_mc, 2, "Heart", "Pumps blood.");
var heart2_Organ:Object = new Organ(_root.heart_mc, 2, "Heart", "Pumps blood.");
var Organ_array:Array = new Array(heart_Organ, heart2_Organ);
the objects that are created are made from the following function:
PHP Code:
function Organ(organ:MovieClip, layer:Number, name:String, info:String) {
var path:String;
this = organ;
this.type = "Organ";
this.active = false;
this.blur = true;
this.name = name;
this.info = info;
if (layer == 0) {
path = "skin_mc";
}
else if (layer == 1) {
path = "muscles_mc";
}
else if (layer == 2) {
path = "cardio_mc";
}
else if (layer == 3) {
path = "bones_mc";
}
depth++;
this.onRollOver = RollOverColor;
this.onRollOut = RollOutAnimation;
this.onPress = Activate;
}
so here s the part i dont get. when i use trace(heart_Organ.name) flash returns 'Heart' as it should. but when i trace(Organ_array[0].name) flash returns 'undefined'. what am i doing wrong? isn't heart_Organ written to Organ_array? im positive it is... can anybody help me out?
Arrays As Objects
If I collect a group of buttons into an array as such...
PHP Code:
var allButtons:Array = ["colorNav1", "colorNav2", "colorNav3", "colorNav4", "colorNav5", "colorNav6", "colorNav7", "colorNav8"];
...why can't I disable or enable those same buttons this way?
PHP Code:
allButtons.enabled = false;
Arrays Of Objects
In a little game we're writing we use arrays of objects. Which are created like this:
Code:
string1 = new Array();
function spawnString1() {
for (var i = 0; i<12; i++) {
var sObj = {};
sObj.MC = _root.createEmptyMovieClip("sphere1"+i, i+50);
sObj.MC.sphereInstance = (Math.floor(Math.random()*3)+1);
sObj.MC.attachMovie("sphere"+[sObj.MC.sphereInstance], "sphere1"+i, i+50);
sObj.MC._rotation = i*30;
sObj.MC._x = 88;
sObj.MC._y = 90;
sObj.MC._xscale = 100;
sObj.MC._yscale = 100;
string1.push(sObj);
}
_root.currentTop = 0;
}
There are two such arrays in the game at any time. (string1 and string2 conveniently)
The objects in the array are coloured balls and in the game the player can change these colours when they are all the same colour the string has to be deleted and a new string should be spawned.
This is where my problems start.
I quickly noticed that deleting string1 (delete string1 doesn't delete its objects. Fair enough a for loop deleting every object manually took care of that.
What I would like to achieve is that once string1 is deleted:
string2 becomes string1
a new string2 is spawned
Spawning a new string is obivously no problem. But what I don't know is how do I copy all the information of string2 to string1.
Obviously a simple =-operater is not enough. I tried to copy the information per object string1[i].MC = string2[i].MC but to no avail. Is there some kind of function to copy this or does it get more complicated?
Arrays Of Objects
I have created a XML file with a list of photo albums that I am reading in. The structure looks like so:
Code:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<photoalbum>
<title>Album1</title>
<pic>
<image>Pic1.jpg</image>
<caption>Some Pic</caption>
</pic>
<pic>
<image>Pic2.jpg</image>
<caption>Another Pic</caption>
</pic>
</photoalbum>
Inside the onLoad event for xmlPhotos I have a loop to stuff the album info into an array called albums... basically a collection of individual albums. I am apparently doing something wrong. The XML portion of the code works just fine... however when I try to increment the PicCount the trace output is "NaN". If instead of incrementing the value I just assign it some value (ie: PicCount=2 it seems to work just fine.
Code:
//Loop through albums
for(i=0;i<xmlPhotos.childNodes.length;i++)
{
albums.push(new Object());
//Loop through each album and grab pic count, title and thumbnail
for(j=0;j<xmlPhotos.childNodes[i].childNodes.length;j++)
{
if(xmlPhotos.childNodes[i].childNodes[j].nodeName=="title")
albums[i].Title=xmlPhotos.childNodes[i].childNodes[j].childNodes;
else if(xmlPhotos.childNodes[i].childNodes[j].nodeName=="pic")
{
albums[i].PicCount++;
trace(albums[i].PicCount);
}
}
}
Is my implementation of objects inside arrays correct? What am I doing wrong?
Thanks!
Objects Or Arrays
I have an app that uses a 2d array which is populated from data in an XML file. The XML file is about 600kb and to sort it seems to take a while. Normally I wouldn't have a problem with this, but the previous version of the app I'm creating used exactly the same XML file and the same code yet read and sorted the information much much quicker. Oh, and its reading it from the same place.
The only difference that I can see is that the new app uses a 2d array whereas the first app used an array with each item turned into an object so for example:
First app array example - details[0].name
New app array example - details[0][0]
Is Flash quicker at sorting objects than arrays? Do you have any suggestions for speeding it up?
Arrays As Properties Of Objects
I have a custom object which has both numbers and arrays defined as properties in its prototype. When I delete an instance of the object, the numbers are deleted as expected, but the arrays are not, and keep their value to the next instance of the object created. Are arrays allowed to be properties of objects, and if so, any ideas why the arrays hold their values, and how I can fix it.
tks
Shared Objects And Arrays
hi!
i used shared objects and have managed to store a single info...i really need to know how to save for instance, ten usernames...i know u have to use arrays, but im not sure how..
any reply would be truly appreciated..
thanks!!
Help With Custom Objects And Arrays
I REALLY need help with this array thing.
I am not a newbie to arrays in other languages, but Flash is throwing me a curve.
I found a tutorial that recommended the creation of custom objects, which I found particularly cool because they're easy to read if you come back to the code months later.
I understand the custom object, and understand the arrays. But I can't quite figure out how to insert and/or access an array within an object structure like I'm trying to build in the code below.
Here's the deal:
I have an array of products constructed using my "product" custom object. Then I have an array of options constructed using my "option" custom object.
Problem: How can I have multiple "option" elements within the "product" array?
What's wrong with this approach?
// Object constructor
function product(id, name, image, price, desc, options) {
this.id = id;
this.name = name;
this.image = image;
this.price = price;
this.desc = desc;
this.options = options; // <---- I want this to be an array of multiple options
}
function option(id, name, image, price, desc) {
this.optid = optid;
this.optname = optname;
this.optimage = optimage;
this.optprice = optprice;
this.optdesc = optdesc;
}
// Create the options array
var options = new Array();
// Create the products array
var products = new Array();
// Populate the options array with options
options[0]=new option("01","OptName 01","optImage01.jpg","000.01","This is the desc of option 01.");
// Populate the products array with products
products[0]=new product("01","Product 01","prodImage01.jpg","000.01","This is the desc of product 01.",options[0]);
// Use the trace function to print out a value in our array
trace("products[0].name = " + products[0].name);
trace("products[0].options = " + products[0].options);
for (i=0; i < products.length; i++) {
trace("products[" + i + "].name = " + products[i].name);
}
Shared Objects/arrays Help.. I Think
Hi- Im designing a website which has a 20 or so different animations on it. I want to use shared objects to determine what animations they user has/hasnt been to. This I understand how to do bt my question is this- how could i set it up so that it works out which animations the user hasnt been too and then suggests 3 random ones to go to that it hasnt previously? Would i need to parse the string in the shared object and put each tag (identifying the animation) into an array and then randomise it to select 3? I really dont know how to go about this, and any thoughts on the matter would be much appreciated!
Many thanks
Chimpo
Parsing Xml Into Objects Or Arrays
I have an xml file that I need to organize into I am guessing arrays as the best method so that when you click a button, it displays certain information in a specific text box.
The xml file is
<menu>
<topitem name="Stream 1">
<interactive type="Topic Overview">
<submenu name="Knowledge Overview" href="http://www.somewhere.com"></submenu>
</interactive>
<interactive type="Summary">
<submenu name="Class Overview" href="http://www.somewhere.com"></submenu>
</interactive>
</topitem>
</menu>
The idea is to create top level buttons that would display the name such as Stream 1. When the user clicks on the Stream 1 button, display all name and href for the Interactive type "Topic Overview" in a listbox and display the name and href for the Interactive type "Summary" in a different listbox.
I have experience parsing simple xml files into flash for menu navigation but I am not sure how to organize this code.
Could someone give me some suggestions as to whether I should make one object with properties for type, name and href or should I have mutliple arrays with one being a multidimensional for the submenu attributes?
Thank you for any suggestions!
Color Objects And Arrays
If I have an array of items the color of which I want to change dynamically, can a make a color object that targets the array or do I have to have a separate color object for each item?
Thanks in advance.
Pushing Objects Into Arrays
I've got an array of objects...a list of quiz questions in the format:
Code:
current_category_questions[i]={question:"question text",
answer1:"answer 1 text", answer2:"answer 2 text", answer3:"answer3 text",
answer4:"answer 4 text",rationale:"rationale text"};
I'm trying to push these questions into a new list of questions. Do I need to initialize an array element as an object before I add an object to it, or can I just push the value like so?
Code:
current_quiz.questions.push(current_category_questions[i]);
I've tried this already and it doesn't seem to work, but I feel like it should. I do this in PHP all the time, can actionscript handle it? Is there some trick to make this work?
Shared Objects And Arrays
input text box and an add button on stage that adds user to the array this work fine
how can i us the add button so that it also searchs and finds the use that have been entered into the array.
any help will be great
var currentUserName:String = "";
var myUsers:SharedObject = SharedObject.getLocal("myUsersName", "/");
// We check if the shared object exists, if not we create the arrays that will store the data
if (myUsers.data.created == undefined) {
myUsers.data.firstnameSO = new Array();
myUsers.data.created = 1;
myUsers.flush();
}
// when the NEW button is pressed we create a new entry
newButton.onRelease = function() {
myUsers.data.firstnameSO.push(firstnameField.text) ;
myUsers.flush();
};
// the function below empty the fields on the right each time an item is removed from the list
function emptyFields(){
firstnameField.text = "";
}
for (var prop in myUsers.data) {
trace(prop+": "+myUsers.data[prop]);
}
Question About Arrays Of Objects
I have an array of objects and I want to take one object in the array that meets a certain criteria and bring that one object to the front of the array while removing it from it's previous position. What is the easiest/best way to achieve this?
the fact that it involves objects seems to complicate things....
thx for the help!
Question About Objects And Arrays
I have an array of objects, and I want to push these objects onto another array. But, its not working. Here is an example of what I'm doing?
var tArray:Array = new Array();
var wArray:Array = new Array();
for (var i = 0; i<10;i++){
tArray = new Object();
tArray.var1 = "Test";
tArray.var2 = "Blah";
wArray = new Object();
}
//this next line doesn't work:
wArray.push(tArray[3]);
//traces undefined
trace(wArray[0].var1);
Will this idea work? What am I doing wrong?
Creating Objects In Arrays
Hi folks
I come up against this problem more and more often as my projects get more ambitions. Tho' I can work round it the code is inelegant, inflexible and repetitive.
So far when creating multiple new objects (of any type), I've had to use:
obj0 = new thing()
obj1 = new thing()
obj2 = new thing()
etc, etc
Rather than repeat the 'new' statement x number of times to create x objects, I would rather use a generalised function to do the job.
I think that means loading the objects into an array
Anyhow... here's my attempt
This code should load sounds into sound objects:
But doesn't work
// path is the path to the sound on the hard disk
// soundNumber = 0, 1, 2 etc
// soundArray an array to hold the sound objects
function setUpSound(path, soundNumber, soundArray)
{
createEmptyMovieClip("mc" + soundNumber,this.getNextHighestDepth());
soundArray[soundNumber] = new Sound("mc" + soundNumber);
soundArray[soundNumber].loadSound(path,false);
soundArray[soundNumber].isPlaying = false
}
any help deeply appreciated
How To Pass Arrays & Objects
Is it possible to pass an array name as an argument into a public function?
ActionScript Code:
outgoing_lc.send( chanID , "slideShowTrigger", "mayorTopic1Array");
with
ActionScript Code:
public function slideShowTrigger( _arrayName:Array ):void {
if (num == 4) {
_arrayName[0]();
num = 1;
} else if (num == 0) {
_arrayName[num]();
num++; } else {
_arrayName[num]();
num++;
}
}
I already have mayorTopic1Array & mayorTopic2Array & mayorTopic3Array populated in the target file.
It seems like i need to pass a reference of some sorts to an existing array inside of the parent swf.
Arrays Of Custom Objects
I can't seem to figure out how to create an array of objects in AS3. For example, if I wanted to create an array of the textField object how would I go about doing it?
Arrays And The Objects That Love Them
PHP Code:
points = [
{ x:25 ,y:375 },
{ x:25 ,y:25 },
{ x:150 ,y:25 },
{ x:325 ,y:300 },
{ x:450 ,y:300 },
{ x:450 ,y:250 },
{ x:325 ,y:250 },
{ x:250 ,y:125 },
{ x:250 ,y:25 },
{ x:525 ,y:25 },
{ x:525 ,y:100 },
{ x:350 ,y:100 },
{ x:350 ,y:125 },
{ x:375 ,y:175 },
{ x:525 ,y:175 },
{ x:525 ,y:375 },
{ x:275 ,y:375 },
{ x:200 ,y:250 },
{ x:125 ,y:250 },
{ x:125 ,y:200 },
{ x:175 ,y:200 },
{ x:100 ,y:100 },
{ x:100 ,y:375 }
];
This was taken from PiXeLWiT's easing example. I'm trying to figure out how he accesses those values by picking apart his code (which can be viewed in this post), and I'm stumped. I've tried...
PHP Code:
//This returns the total length, which is correct
trace("points.length = "+points.length);
var myLength = points.length;
var m = myLength[1];
//This doesn't work, however... :-(
trace("m.x = "+m.x);
...and now I come to you for help. I went through Colin Moock's Actionscript book, and haven't found a reference to this style of Array work yet; it's not a named Array element, I don't think, and PiXeLWiT said that the x/y values are objects, so how do I reference objects in an array?
Question About Objects And Arrays
I have an array of objects, and I want to push these objects onto another array. But, its not working. Here is an example of what I'm doing?
var tArray:Array = new Array();
var wArray:Array = new Array();
for (var i = 0; i<10;i++){
tArray = new Object();
tArray.var1 = "Test";
tArray.var2 = "Blah";
wArray = new Object();
}
//this next line doesn't work:
wArray.push(tArray[3]);
//traces undefined
trace(wArray[0].var1);
Will this idea work? What am I doing wrong?
Question About Arrays Of Objects
I have an array of objects and I want to take one object in the array that meets a certain criteria and bring that one object to the front of the array while removing it from it's previous position. What is the easiest/best way to achieve this?
the fact that it involves objects seems to complicate things....
thx for the help!
Shared Objects/arrays Help.. I Think
Hi- Im designing a website which has a 20 or so different animations on it. I want to use shared objects to determine what animations they user has/hasnt been to. This I understand how to do bt my question is this- how could i set it up so that it works out which animations the user hasnt been too and then suggests 3 random ones to go to that it hasnt previously? Would i need to parse the string in the shared object and put each tag (identifying the animation) into an array and then randomise it to select 3? I really dont know how to go about this, and any thoughts on the matter would be much appreciated!
Many thanks
Chimpo
Shared Objects With Arrays
I have two arrays in my frame 1 root timeline
clips[menu,middle,background,bottom]
colours['0x336666', '0xCC9933', '0x1234cc', '0x1111BB']
When a user clicks on certain buttons it adds colors to the colours array, at specific places
on(release){
colours[1]=0x123456
}
on(release){
colours[3]=0x546534
}
Several buttons will add colour value elements to the array
When the user hits the 'save' button the 'colours' array should be saved on his computer as a saved object (.sol)
When the user returns, the array elements he saved should be loaded into the colours array.
How should I do this?
Shared Objects Arrays
Hi,
I'm probably being really thick but I've been banging my head against the desk for ages over this one.
Basically I have a list box that I've set up for a user to add files to.
I want to then send these file names to the local shared object so I can get them back at another point in the movie (its a myAccount page where they can see the filenames they've entered.)
I can't seem to get my head around
a> Setting an array in the shared object that I can add to and change.
b> sending the labels and data from the list box to the shared object.
I'm new to action script, so I could just be using the wrong code. This is what I'm doing.
updateListener = new Object();
// function for adding to list
updateListener.click = function (evt){
cardsFiles_lb.addItem(cardsFile_txt.text);
cardsFile_txt.text = " ";
trace (cardsFiles_lb.getLength());
trace (_global.cardsFiles.data.aCardsFiles(i));
flushcardsFiles();
}
//assigns the function to the button
add_btn.addEventListener ("click",updateListener)
deleteListener = new Object();
// function for removing from list
deleteListener.click = function (evt) {
cardsFiles_lb.removeItemAt(cardsFiles_lb.selectedIndex);
trace (cardsFiles_lb.getLength());
flushcardsFiles();
}
//assigns the remove function to the button
remove_btn.addEventListener ("click",deleteListener);
_global.cardsFiles = SharedObject.getLocal("cardsFiles", "/");
if (_global.cardsFiles.data.created) {
for (var i:Number = 0;
i < _global.cardsFiles.data.aCardsFiles.getLength();
i++)
cardsFiles_lb.addItem(_global.cardsFiles.data.aCardsFiles(i))
} else {
_global.cardsFiles.data.created = true;
flushcardsFiles();
}
flushcardsFiles = function (evt){
for (var i:Number = 0;
i < cardsFiles_lb.getLength();
i++)
_global.cardsFiles.data.aCardsFiles.push(cardsFiles_lb.getItemAt(i))
}
Sorry to chuck all this code in, but I'm getting to my wits end. Also probably making myself look stupid!!
Cheers
Tim
Manipulating Arrays And Objects
Game,
I have 2 arrays:
BlackNumChips = [0,0,0,0,0,0,5,0,3,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,2,0]
WhiteNumChips = [0,2,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,3,0,5,0,0,0,0,0,0,0]
Ok, player rolls 2 dice, and moves one man an amount equal to one die.
Player again moves one man amount equal to second die. Turn is over.
A Black move is legal if it goes left, down the array.
A White move is legal if it goes right, up the array.
How would you code this depending on what "position" was clicked and what "position" mouse released on.
Example:
1. User selects a point on the board(which coincides with element#) taking a chip.
2. User releases mouse over a point effectively droping a chip.
Anyone know the answer?
[tip] Cloning Arrays And Objects
Hi, guys.
Just another AS tip.
If you want to clone/duplicate an Array instead of simply creating a reference to it, then you can do this:
ActionScript Code:
var newArray:Array = [].concat(oldArray);
Here's an example of what normally happens (referencing):
ActionScript Code:
// our original array
var original:Array = [1, 2, "foobob"];
// creates a reference to the original array
var referenced:Array = original;
// changes both arrays
referenced[2] = "doodog";
trace(original[2]); // output: doodog
trace(referenced[2]); // output: doodog
Here's an example of cloning:
ActionScript Code:
// our original array
var original:Array = [1, 2, "foobob"];
// clone the original array
var cloned:Array = [].concat(original);
// only changes the cloned array
clone[2] = "doodog";
trace(original[2]); // output: foobob
trace(cloned[2]); // output: doodog
The same thing happens with Objects, but cloning them needs a slightly different approach:
ActionScript Code:
var cloneObject(original:Object):Object
{
var cloned:Object = {};
for(var prop:String in original)
{
cloned[prop] = original[prop];
}
return cloned;
}
var original:Object = {a:1, b:2, c:3};
var cloned:Object = cloneObject(original);
Doing things that way is fine, until you need to start cloning multi-dimensional arrays and objects. Although the methods up there ^ will still work, any arrays or objects in the original array/object will not be cloned, they will still be referenced.
That's about it for now.
Deleting Objects / Arrays
Hi all,
I have several large arrays sat in _root, and I want to be a good coder and clean up after myself when I don't need them any longer.
I cannot find any kind of "delete" keyword.
The best I can do is assign "null" to the array variable, but I am dubious as to whether this is deleting the actual array object as arrays are reference objecst.
Does Flash have some kind of garbage collector like Java?
Cheers,
Lister
Passing Objects With Arrays
i made a dataload class for my flash site which loads a php page and creates an object with arrays in (news, menu, bio, ...).
I can make the dataload object and get the object witth everything in
but from the moment I pass my object from my dataload class to the timeline I can't access the arrays in the object (everything is accessible in the class itself)
I find it strange that I can't pass an object with arrays in it to the timeline in a proper manner
ActionScript Code:
var pierot_obj:dataTous = new dataTous("php/tous_pierot.php");
var alles = pierot_obj.getDataObject();
when i trace alles.mmenu (the array with menu items) i get undefined
but when i trace the same in my dataTous class (dataload) I get the array with menu items
this is how i pass teh object to the timeline
ActionScript Code:
public function getDataObject():Object {
return xmlDataObject;
}
My Objects Are Sharing Their Arrays
Hi
I am having trouble with using arrays within objects. In this example I create peter and julie, both objects of my 'testObject' class. Each object of this class has an array. The problem is that when I change peters array, julies array changes too. Is there any way around this. I need both objects to store thier own independant array.
_global.testObject = function(arr) {
this.arr = arr;
};
testArray = new Array(1, 2, 3, 4);
julie = new testObject(testArray);
peter = new testObject(testArray);
peter.arr.push("I want this to only append to peters array");
trace("julies array: "+julie.arr);
trace("peters array: "+peter.arr);
Any suggestions would be appreciated.
Arrays With Created Objects
i'm just kind of curious about this, interested in a little feedback. is this a bug or what? i have a function which draws an object with the built in api. i tried first tweening some of those objects with mc_tween, which i finally got to work, but only after a LOT of playing around.
something like the following would not work. I have several arrays with similar content. Ie. clipList1, clipList2... so I'm passing the "clip" information to the function and then concatenating the "List1" info onto the passed "clip". But this doesn't work.
Code:
eval(clip+"List1")[0].alphaTo(100,1,"linear")
I tired a lot of alternates and finally got something to work.
Code:
var myList = eval(clip+"List1");
eval(myList[0]).alphaTo(100,1,"linear")
This same problem occured when trying to add textfields to my created objects, which i suppose would be more likely for someone to do than adding mc_tween events to objects. just curious if someone else out there has had the same problems or if there's a logical reason for this. thx.
Collisions With Duplicated Objects (arrays?)
I'm trying to make a breakout type game. But some of the blocks I just duplicated over a couple of times, and the ball only collides with the original block.
// set the x and y property of the circle movieclip
setProperty ("/circle", _x, x);
setProperty ("/circle", _y, y);
// creates a random number with this function
function random_fun () {
r = random(10);
return r;
}
// check if circle has hit border4 if hit change x and y values
if (circle.hittest(border4)) {
tellTarget ("/circle") {
gotoAndPlay (2);
}
flag = 1;
rand = random_fun();
}
// check if circle has hit border3 if hit change x and y values
if (circle.hittest(border3)) {
tellTarget ("/circle") {
gotoAndPlay (2);
}
flag = 2;
rand = random_fun();
}
// check if circle has hit border2 if hit change x and y values
if (circle.hittest(border2)) {
tellTarget ("/circle") {
gotoAndPlay (2);
}
flag = 3;
rand = random_fun();
}
// check if circle has hit border1 if hit change x and y values
if (circle.hittest(border1)) {
tellTarget ("/circle") {
gotoAndPlay (2);
}
flag = 4;
rand = random_fun();
}
// check if circle has hit paddle | If hit change x and y values
if (circle.hittest(paddle)) {
tellTarget ("/circle") {
gotoAndPlay (2);
}
flag = 4;
rand = random_fun();
}
// check if circle has hit red block | If hit change x and y values
if (circle.hittest(blockRed)) {
tellTarget ("/circle") {
gotoAndPlay (2);
}
flag = 5;
rand = random_fun();
}
// set the x and y co-ordinates according the the place where the circle hit
if (flag == 0) {
x = x+rand;
y = y+5;
}
if (flag == 1) {
x = x+5;
y = y-rand;
}
if (flag == 2) {
x = x-5;
y = y-rand;
}
if (flag == 3) {
x = x-rand;
y = y+5;
}
if (flag == 4) {
x = x+5;
y = y-rand;
}
if (flag == 5) {
x = x+rand;
y = y+5;
removeMovieClip ("redBlock");
}
// end action script
**I also need to know how to remove the blocks once they've been hit.
Thanks in advance
OOP Problem: Loading Objects Into Arrays
Hi!
I have a class (Book) that has an array as atribute (slides). When i try to load slides objects into this array, i can´t access them... Can you help me???
// Class Slide
Slide=function(picP,picG,xPos,yPos){
this.picP=picP;
this.picG=picG;
this.xPos=xPos;
this.yPos=yPos;
}
// Class Book
Book=function(){
this.slides=new Array();
}
Book.prototype.addSlide=function(slide){
this.slides.push(slide);
}
// create an empty book
book=new Book();
//create slides and insert them into the book
for(i=0;i<5;i++){
slide=new Slide("picP_"+i,"picG_"+i,i*10,10);
book.addSlide(slide);
//this doens´t work!!!!
trace(book.slides[i].picP);
}
Passing Arrays To And From Shared Objects
I have two arrays in my frame 1 root timeline
clips[menu,middle,background,bottom]
colours['0x336666', '0xCC9933', '0x1234cc', '0x1111BB']
When a user clicks on certain buttons it adds colors to the colours array, at specific places
on(release){
colours[1]=0x123456
}
on(release){
colours[3]=0x546534
}
etc, etc
Several buttons will add colour value elements to the array
When the user hits the 'save' button the 'colours' array should be saved on his computer as a saved object (.sol) for the sake of arguments called 'scheme'
When the user returns, the array elements he saved should be loaded into the colours array.
How should I do this?
Can Arrays Hold Sound Objects?
I have several sounds that I want to have loaded at the same time. I also want those sounds to be available through a scheme like an array of sounds so that I can call them by number.
I've created numbered names for the duplicateMovie() function, such as
mcNam = "bmov" + index;
duplicateMovieClip("bmov", mcNam, (30 + index));
Can anyone suggest how to do this with sound objects so that I can address them something like :
for i from 0 to the last sound
("sound"+i).start;
Arrays And Local Shared Objects :)
Hello!
I am new to actionScripting, and am in a little over my head on this one...
I have a CD-Rom project where the last frame that a user was on is stored in a local shared object so that the movie starts back up when they left off the next session.
Now...I have to take this up a bit. Because different users will be on the same machine, I need for the user to be able to dreate a username...and then be able to "log-on" and have the shared object load all the correct info.
This seemingly could be done with multidimentional arrays. I have stored a single value to a shared object...but how do you set up arrays with them?
Thanks!
Kevin
Arrays, Sort By Objects _y Position ?
I have an array called "water"
In this array I currently have 10 obejcts which are MovieClips. Now i want water to be sorted in the way, that the object which contains the movieCLip with the highest _y position ( Lowest on screen) is first.
Does anyone know how to do that??
Sorting Multidimensional Arrays/Objects
I have been thinking about this for a while now. I want to be able to sort an array of objects depending on the object index, but, not just one of their indexes.
for example:
Code:
object1 = {streetNum:12, road:'Truro', suburb:'Sandringham', city:'Auckland', price:5000000};
object2 = {streetNum:2, road:'Wayside', suburb:'CBD', city:'Auckland', price:250000};
objectArray = [object1, object2];
As above i need to be able to sort the objectArray by streetNum or road or any combination of indexes.
The objects are being populated from a mysql database using php, would i be better to do it with mysql or php? I would rather do it all in flash so i only have to load the data once then can reshuffle within flash.
Thanks in advance.
Objects As Associative Arrays And Variables
I am trying to take form fields that were typed in and have them sent to an Object as an associative array. I think all I need to know is the method and syntax. I have 3 variables in the form, (Home1Name, Home1Number and Home1Position). I am trying to create a Player object for each player involved and then have all the info for that player associated with that one object.
Also, the trace tool shows me that the variables in the form fields are working, but all of the keys on the object show as undefined. Still new to these aspects of actionscript so explanations are most appreciated.
var homePlayer1Obj:Object = new Object();
// Adding property definitions
homePlayer1["playername"] = Home1Name;
homePlayer1["playernumber"] = Home1Number;
homePlayer1["playerposition"] = Home1Position;
trace(homePlayer1["playername"]);
trace(Home1Name);
trace(homePlayer1["playernumber"]);
trace(Home1Number);
trace(homePlayer1["playerposition"]);
trace(Home1Position);
|