Object Data Member Not Changing When Assigned Value
Hi,
So I've run into a problem with assigning a value to some of my object's data members.
Here's what's going on:
I have a class called Tile. Here is the code for the class (just the part that you need to see):
public class Tile extends MovieClip {
private var testVar:String;
public function Tile() {
testVar = "initialized testVar";
this.addEventListener(MouseEvent.CLICK, mouseClickHandler);
}
private function mouseClickHandler(event:MouseEvent):void {
trace(testVar);
}
public function setTest(s:String):void {
testVar = s;
}
}
Out side of this class I make two simple calls. One to initialize the object and the other to call the function (the object is already present on the stage btw so I CAN click it). The call is:
var myObject:Tile = new Tile();
myObject.setTest("cool");
Now when I run the program and I click on myObject, it spits out:
initialized testVar
click it again... and again... and again lol. Same thing over and over. So I thought maybe my call outside the class was somehow incorrect. I made a trace within the setTest function so that it looked like this:
public function setTest(s:String):void {
testVar = s;
trace (testVar);
}
This time it spits out:
cool
Then when I click it always gives me:
initialized testVar
Why won't my data member change?
icekube12jr
KirupaForum > Flash > ActionScript 3.0
Posted on: 07-18-2007, 03:29 PM
View Complete Forum Thread with Replies
Sponsored Links:
Changing The Variable Assigned To A TextField?
Hey everybody. I was hoping if someone could help me out with this. I have a textfield named "text1" that is assigned a variable. I need to change this variable at a certain point to something else. I'm using MX and I know that they have the command "TextField._variable", which assigns a textbox a certain variable.
What I did, I created a button instance and assigned it the action:
Code:
on (release) {
text1.TextField._variable = "Display";
}
However, this is not changing the variable to "Display". Anybody know what I'm doing wrong? I'm not all that good with actionscript so I prolly might have some simple error.
View Replies !
View Related
Attach A MC To An Object Assigned To Class By Name
I have created an Actionscript 2.0 class and using the convention:
ActionScript Code:
var someVar=new menuItem(blah blah blah);
I have great success, but when I try:
ActionScript Code:
var someVar:menuItem = new menuItem(blah blah blah);
and then look at my MovieExplorer tab, I have multiple sets of recursive elements. Why?
Also, when I drop a MovieClip from the library that has been assigned to the custom AS2.0 class that I have defined, is there any way for the class to find out the objects name if it was added manually to the timeline?
I have created these custom icons that have linkageID's related to the name of their parent clip. (i.e. biography.lbl) is a LinkageID for the biography icon. It works great when I use AS2.0 in the MovieClip to attach the new menuItem's MovieClip to the stage, but when I add it manually, I can't figure out how to make the class constructor or any method to look at the object's name and then attach a clip to itself based on its name?
Let me know if I have you completley lost. I can try to explain it another way, maybe. Thanks in advance for all of your help.
Rowdy
View Replies !
View Related
Changing A Cast Member/sprite
Before I begin, forgive my lack of knowledge on this, my background is Lingo so Im not familar with actionscript or flash terminology at all. Here gos anyways-
Im essentialy tasked with having an animation clip loop (xmas snowing scene) with 'season greetings' in several languages automatically rollingover everytime the movie-loops. My question is- how do I change the 'season greetings' member from one to another each time the movie loops at say frame 50? Any clues to the correct syntax would help me on my way.
View Replies !
View Related
Dynamically Assigned Movieclip Variable Is Not Taking In Object Reference
I have the code below that's supposed to assign the reference of a programmatically created textfield(_root["logoInfo"+i+"_txt"]) to a movie clip variable(_root["logoInfo"+i+"_mc"].info) created at runtime.
when i trace _root["logoInfo"+i+"_txt"], the reference checks out okay but when _root["logoInfo"+i+"_mc"].info is traced, it returns undefined
code:
for(var i=1;i<=logoNum;i++){
_root.createTextField("logoInfo"+i+"_txt", i, 0, 0, 100, 20);
_root["logoInfo"+i+"_mc"].info = _root["logoInfo"+i+"_txt"];
trace(_root["logoInfo"+i+"_mc"].info);
}
View Replies !
View Related
Assigning Value To Object Member Variable?
This example comes from "Learning Actionscript 3.0" pp 138-9:
Code:
public function Particle(xp:Number, yp:Number, xvel:Number, yvel:Number, grav:Number, col:uint) {
_xpos = xp;
_ypos = yp;
_xvel = xvel
_yvel = yvel
_grav = grav;
var ball:Sprite = new Ball();
addChild(ball);
x = _xpos;
y = _ypos;
alpha = .8;
scaleX = scaleY = Math.random() * 1.9 + .1;
var colorInfo:ColorTransform = ball.transform.colorTransform;
colorInfo.color = uint(col);
ball.transform.colorTransform = colorInfo;
addEventListener(Event.ENTER_FRAME, onRun, false, 0,
true);
What not simply
Code:
ball.transform.colorTransform.color = uint(col);
instead of the actual three lines of code in bold?
When I try my substitution, the assignment fails. Why? And why the necessity for the roundabout assignment? Thanks, I'm coming to AS3 from other languages (not Javascript), so any understanding would be appreciated.
View Replies !
View Related
Two Object Referencing Same Member Array?
I'm working a neural network project and my basic architecture is this:
1. Neurons
2. Neuron Layer (basically an array of neurons)
3. Neural Network (basically an array of Neuron Layers)
When I reference the first Neuron Layer's array.length it gives me the total number of neurons in the network rather than what the number of neurons in the first layer should be. The same thing happens for the second layer and each subsequent layer should there happen to be more. I've added trace statements to the Neuron Layer constructor that tells me a neuron has been added and I've also added a trace statement after the first neuron layer is added and the second neuron layer and I get the correct number of "neuron added" statements before the "first layer added" statement and the correct number for the second layer as well. This pretty much assures me that the actual number of neurons in each layer is correct when the first layer is created but somehow the number of neurons in the first layer and subsequent layers is actually becoming the number of neurons total. The only thing I can figure out is that somehow, the first neuron layer object is referencing the same neuron array member as the second neuron layer object. Is this possibly what is happening?
View Replies !
View Related
Create An Array Object As A Member Of A Movieclip
Hi all
I'm having trouble wrapping my head around creating an array as a data member of a movieclip, i.e. dynamically adding it to that movieclip depending on data brought in at runtime.
Is it possible? Would I have to create an array seperately first and then somehow assign it to a new (typeless) data member of the movieclip?
Thanks in advance for your help.
-Nick
View Replies !
View Related
How Can Access A Class's Member From An Event Of Member Movieclip ?
Hi,
How can I access sLink at the onPress handler ?
PHP Code:
class CSM {
private var oMovie4TextField:MovieClip;
private var sLink; // I would like to access this at the onPress handler
...
...
public function Initializaton()
{
...
...
this.oMovie4TextField = _root.createEmptyMovieClip('some_mc', _root.getNextHighestDepth());
...
}
this.oMovie4TextField.onPress = function ()
{
...
...
getURL(this.sLink, "_self"); // not works because this means oMovie4TextField
...
};
}
View Replies !
View Related
Changing Data In A Text Box
Hi,
I want to be able to scroll through a list of figures in a dynamic text box using buttons calle shutterUp and shutterDown. This should change the number in text box between these buttons.
Is there any other way to do this other than using the IF function?
ie. _root.shutterUp_btn.onRelease = function() {
if (shutter.text == '1/1000') shutter.text = '1/2000'
}
???
thank you
View Replies !
View Related
Please Help Data Changing In URLRequest
I apologize if this appears as a second post. My first attempt didn't show up in the forum.
I'm trying to pass a encrypted string through Flash to a PHP page. It appears to be reaching Flash ok, but when it arrives at the PHP page it's a completely different string. I have no idea how or why this is happening.
If anyone has any ideas about the specific working of the URLRequest and URLVariables objects and what they do to data, please direct me to an explanation. I'm trying to get an app ready for testing tomorrow, and this delay is backing up the works. Any help would be appreciated.
Regards,
Dave Spaar
View Replies !
View Related
Data Loading Not Changing
3 dynamic text fields (caption, caption1 and caption2) on stage loading from XML. Data loads fine. However buttons not changing data on click.
AS
Code:
var x:XML = new XML();
x.ignoreWhite = true;
var e:Array = new Array();
var e1:Array = new Array();
var e2:Array = new Array();
var whatOn:Number;
x.onLoad = function() {
var p:Array = this.firstChild.childNodes;
for(i=0;i<p.length;i++) {
e.push(p[i].attributes.english);
e1.push(p[i].attributes.english1);
e2.push(p[i].attributes.english2);
}
caption.text = e[0];
caption1.text = e1[0];
caption2.text = e2[0];
whatOn = 0;
}
x.load("text.xml");
p.onRelease = function() {
if(whatOn > 0) {
whatOn--;
caption.text = e[whatOn];
caption1.text = e1[whatOn];
caption2.text = e2[whatOn];
}
}
n.onRelease = function() {
if(whatOn < p.length-1) {
whatOn++;
caption.text = e[whatOn];
caption1.text = e1[whatOn];
caption2.text = e2[whatOn];
}
}
Data loads however buttons arent changing to next data provided by XML. Anyone got any ideas.
Thanks
MT
View Replies !
View Related
Changing An Array Result From An Array Object To A MovieClip Object
Anyone know how I can do this?
I have 3 arrays.
Quote:
//set info into arrays
wpInstName = new Array();
for(i=0; i<_global.wpCount; i++); {
wpInstName[i] = _global.newWP;
trace(wpInstName.join(" + "));
}
wpPositionX = new Array();
for (i=0;i<_global.wpCount;i++); {
wpPositionX[i] = _global.wpXpos;
trace(wpPositionX.join(" + "));
}
wpPositionY = new Array();
for (i=0;i<_global.wpCount;i++); {
wpPositionY[i] = _global.wpYpos;
trace(wpPositionY.join(" + "));
}
I need to use the current value of wpInstName[i] to change the _x and _y properties of an attached movie clip.
I have tried allsorts but it still treats the data as an Array object.
I have tried making a new Object and gave it the wpInstName[i] as a value to add properties too but im not sure if I did it right(it didnt work so I guess not ).
If anyone could help it would be greatly appreciated
Thnx
View Replies !
View Related
Changing Object Type
In the properties pane, you can select and object and specify wheather you want it to be a graphic, movie clip or button. Is there any way of changing this property in with ActionScripting?
Thank you
View Replies !
View Related
Changing Variables In An Object?
I'm trying to store some variables in an object and then change them later. This object will act like a storage container for temporary variables, so that swfs loaded in and out of the timeline can read and write to it.
Here's some code I'm using to create and test the object:
PHP Code:
list_object = new Object ();
list_object.item_1 = "a";
list_object.item_2 = "b";
list_object.item_3 = "c";
list_object.item_4 = "d";
list_object.item_5 = "e";
list_object.list_items = 5;
So when the swf loads into the timeline, it looks for the object. If it finds the object, then it will do what it needs to do with the object's variables. If the swf does not find the object, it will download the data from a text file on the server and then create a new object that it can use later.
I'm trying to change the values of the object through a loop, but have had no luck at all. I've tried everything I can think of. Here's some code I'ved used to test:
PHP Code:
generic_object = eval ("_root." + this._name + "_object");
for (i = 1; i <= generic_object.list_items; i++) {
var previous_item = eval ("item_" + (i - 1);
var item = eval ("item_" + i);
generic_object.item = generic_object.previous_item;
}
I've also tried it this way:
PHP Code:
generic_object = eval ("_root." + this._name + "_object");
for (i = 1; i <= generic_object.list_items; i++) {
_root [this._name + "_object.item_" + i] = eval ("_root." + this._name + "_object.item_" (i - 1));
}
I've tried other code as well, but no luck.
In a nut shell, I'm just trying to reassign the values of the variables within an object from a different movie clip/level/timeline.
Can anyone shed some light on this for me?
Thanks,
Cooper
www.pigdogtoad.com
View Replies !
View Related
Changing Object Depth
hi, I have different background thatt slides into the screen when a button is pressed. How do I alternate the depth of the backgrounds when different buttons are pressed? thanks! Oh, I'm using flash 5
View Replies !
View Related
Changing The X,Y Of An Object Problem
What Im trying to do is change the X,Y of an object when the frame is returned to. here is the set-up. I have in one fla with no loading MCs, on my main timeline a board game. you move the game piece over a sqare and you are sent to a mini-game. The mini-game lives on a frame in the root timeline as a single frame. and has for example the path. _root.mini_game_1 . the user plays the game then returns to the board game. I would like to be able to have the game piece remain on the bord game square it was left on, but it returns to its origional X,Y. As a note the piece is by default placed on the start sqaure. I tried to do something like this on the return button within the mini-game but it doesnt change a thing.
Code:
on(release){
_root.gotoAndStop("game_board");
_root.game_piece._x = 100;
_root.game_piece._y = 100;
}
sorry for the long winded explanation but my fla is already too big to post. I hope someone out there understands what Im trying to do and can lend a hand
Cheers
Mark
View Replies !
View Related
Changing An Object's Color
i have this old piece of code:
Code:
if (Number(charinline)<=Number(linelen)) {
duplicateMovieClip("/fx_" add fx add "_0", "char" add i, i);
set("/char" add i add "/letter/lettercolor:char", key);
setProperty("/cursor", _x, Number(startx)+Number(charinline*kerning)-20);
setProperty("/char" add i, _x, Number(startx)+Number(charinline*kerning));
setProperty("/char" add i, _y, Number(starty)+Number(linenum*linespace));
charinline = Number(charinline)+1;
i = Number(i)+1;
}
... which duplicates and places mc named "char[i]" on the stage based on predetermined _x & _y values, now i need to change the color of said mc. how can i do that? i've been trying to find a way but i gave up after 3 hours.
any help will be greatly appreciated
thanks much
- w
View Replies !
View Related
Changing Alpha On An Object
Haven't posted here in like 2 years...thanks for being here
I have a problem displaying multiple objects. I have mutiple objects stacked over one another all with their alpha=0. My intention is when one selects a checkbox, one of these objects becomes visible by changing the alpha from alpha=0 to alpha=70 (see code below). Two things: in some cases, on an LCD screen (laptop) one can still see the objects where alpha=0. The second thing is that I get interference from all the stacked objects when one is selected. I am thinking that I want to use something where the objects are in a state of "off" rather than alpha=0? Any thoughts?
Here is a msword document illustrating the above points:
http://www.netwiz.net/~cheez/alpha_issue.doc
Here is the native FLA:
http://www.netwiz.net/~cheez/demo_spectra.zip
Here is the prototype website:
http://www.netwiz.net/~cheez/demo_spectra.html
Here is the code in question:
ActionScript Code:
if (checkbox.getValue() == true) {
_root[spectraGraphic+"em"]._alpha = 70;
_root[spectraGraphic+"ex"]._alpha = 80;
getData(x, spectraGraphic);
dimSpectra();
order++;
orderArray[order] = spectraGraphic;
}
if (checkbox.getValue() == false) {
_root[spectraGraphic+"em"]._alpha = 0;
_root[spectraGraphic+"ex"]._alpha = 0;
}
Any suggestions or comments would be greatly appreciated.
Thanks,
Cheez
View Replies !
View Related
Changing Object Color With AS
hi I am trying to make a smooth color transition using AS2
the way I have now the mc changes colors just fine, but not smooth like when you use tween. I know there is a 'get Transform' function but I don't know how to apply maybe someone has an example??
Code:
function changeBG(col) {
var c = new Color(_root.bg);
c.setRGB(col);
}
changeBG(0xCC3366);
View Replies !
View Related
Can I Get Some Help With Changing The Color Of An Object?
I'm trying to make the following - I have 5 buttons corresponding to five sections in my Flash movie..I want to make it so, that when I click on a button it background color changes(to show that it was clicked and I'm in that section)...
The button is located inside a movieclip(not in the root timeline)...
For the purpose I converted the background of the button (which I want to change) to a movie clip, so I could use the "setRGB" command, but still I'm doing something wrong and nothing happens...
Can someone explain to me clearly the mechanism of changing the color of a movie clip?
Thanks in advance!
View Replies !
View Related
Changing The Color Of An Object
Hi
I want to make something like a children's paint book. The user will choose the color from a palette and when she clicks an object, that object will seem in that color.
Anyone knowing a tutorial about it, or any suggestions on how to accomplish this?
Thanks in advance
View Replies !
View Related
Changing Object Properties
hi all---
can anyone tell me why when i create a group of objects:
for (var i = 1; i<11; i++) {
this['answer'+i+'Object'] = _parent.xch['answer'+i+'Object'];
}
and then change a certain propety value on all of them
for (var i = 1; i<11; i++) {
this['answer'+i+'Object'].correct = 5;
}
it worx fine in the init() function but then when i try to use the exact same 'for' loop to change the values again nothing happens. ex:
function setCorrect(){
for (var i = 1; i<11; i++) {
this['answer'+i+'Object'].correct = 0;
}}
any suggestions would be greatly appreciated. the only way i can get the reset to work is to set each object property individually. ex:
answer1Object.correct=0;
answer2Object.correct=0;
answer3Object.correct=0; .......
thanx
View Replies !
View Related
Please Help Getting Data Out Of XML Object?
Hi,
I am very new to XML. Below is where I'm up to. I am struggling to trace out the data like. Can someone help me with my paths to the various parts? I'm not sure if it is due to Flash code or the XML structure that is causing the problem.
Many thanks
Ol
__________________________________________________
__________________
I have uploade the XML here:
http://www.araj21.dsl.pipex.com/dealers_RO.xml
__________________________________________________
__________________
// FLASH CODE
dealers_xml = new XML();
dealers_xml.onLoad = startMovie;
dealers_xml.load("dealers_RO.xml");
dealers_xml.ignoreWhite = true;
//
// Show the first slide and intialize variables
function startMovie(success) {
if (success == true) {
//trace(dealers_xml.firstChild.firstChild.firstChild );
//trace(dealers_xml.firstChild.firstChild)
trace(dealers_xml.firstChild.firstChild.firstChild )
}
}
View Replies !
View Related
Changing Object Colour With Scripting
I've searched around the site for a few hours and haven't found
an answer to my problem.
I have an object, say a house. The house is one color. But I want the user to be able to cycle through, using buttons, ( <- ) and ( -> )
to change the colour of the house. I want to do this using action scripting.
Any help would be appreciated.
Thanks...
View Replies !
View Related
Changing The Color Of An Object At Every Execution
I have a problem:
I have one file, template.as, this file keeps color configuration to make changes of my site.
I would like to know if it is possible to change color of an object every time of execution (run time).
I am using setRGB() function to make these changes.
The variable that defines the template that will be used is loaded with loadVariablesNum() function.
My script works only when I compile my movie clip (generate .swf)
I want to change the colors without having to "compile" my movie every time.
If someone can help me with other functions or any other way to do this, I will be very grateful.
Thanks
View Replies !
View Related
Changing An Object Property With It's String Name?
If I have the full path name of an object like:
var1 = "parentObject.firstChild.secondChild";
and I want to change the value:
parentObject.firstChild.secondChild.price
How can I do this with access ONLY to the string variable var1?
My situation is more complicated than given above... but essentially it's the problem given above, where I only have access to the string variable.
I've tried something like:
this[var1].price
But that doesn't work.
I can get access to the variable with eval(var1 + price)... but with the rules of the use of eval changed from Flash5, I can't use this.
Any ideas?
Does anyone understand my mad problem?
Any help would be appreciated.
Thanks.
OM
View Replies !
View Related
Changing External Object With Button
I'm trying to create avatars for my new site. I want to make it work like gaia onlines avatar creator. (www.gaiaonline.com). Right now i'm just trying to make a button that changes the frame in a different (separate element) movie clip. I think i would creat a layer for the different parts of the body. (hair for example) I load the hair layer with different hair styles, then I set the button to change the different frames that have the different hair styles.
It all works in theory, but what are the actions I need to do this. Thanks for your help.
Kevin
View Replies !
View Related
Gradually Changing Height Of An Object.
Hi guys,
I'm creating a flash game for kids. The basic idea is you click on various objects and a thermometer shows how hot the object is. Now I have got as far as the thermometer changing height for each object but what I want is for the thermometer to gradually increase or decrease when you click on an object rather than jumping to the right temperature immediately.
I am looking for either code examples or a tutorial to solve this problem rather than an explanation of the logic involved as I have worked that out already.
Thanks in advance for your help.
PS I'm running MX04 Pro.
View Replies !
View Related
Changing An Object's Coords In An Array?
Code:
empty.attachMovie("item1", arr.push("item1"+i), getNextHighestDepth());
arr[i]._y -= 5
i++
Why cant i do that?
even if i dont use arrays and just do
Code:
empty.attachMovie("item1", "item1"+i, getNextHighestDepth());
"item1"+i._y -= 5
i++
it doesnt work. Am i missing something obvious???
View Replies !
View Related
Changing Color Of Imported Object
Hi,
i am trying to change color of imported swf file from another swf, let say i have a swf names fileparent and inside mc with instant name stage. in that stage i have some controls of color boxes i have imported another swf using AS on stage. imported swf have some layers with different objects of different colors i want to change color of every object separately. i dont know how to access that object inside imported swf.
just need to know the way to get inside imported object.
see an example here
http://www.bluecotton.com/studio.htm...175&garColor=1
thanks in advance
View Replies !
View Related
Changing Object Colors With Actionscript
Hi guys... im new to the forum and consider myself a novice actionscripter... i have lofty goals in terms of the script that im trying to write, admittedly my understanding at any given moment may be zero... anyway here is what id like to accomplish with the click of a button:
id like to change the color of my movieclips when the user clicks a button also in that moment id like to load and unload movies into an empty clip in my main timeline? am i in over my head as a beginner or is there a short a sweet code for this? -if i have to i will create various scenes and labor over it to reach my desired effects but i know through actionscript there has to be a better way -can anyone point me in the right directions? please?
View Replies !
View Related
Changing Object Visibility With Last Xml Sibling
Ok, I'm newish to Flash, so this is probably a no brainer.
In the script below, I want to automatically set the 'next_btn' visibility to 0 when the last xml sibling is loaded. I suspect that I need to write another function, but that's where I'm getting confused. I think it would look something like...
function hideButton(newSlideNode)
{
if(nextSlideNode.nextSibling == null)
{
setProperty("next_btn", _visible, 0);
}
}
...but I'm far from convinced this is right, and even if it is, I'm not sure where I need list the call on it. I apologise in advance for what is probably a simple question!
Cheers,
Ky
function startSlideShow(success)
{
if (success == true)
{
rootNode = slides_xml.firstChild;
totalSlides = rootNode.childNodes.length;
firstSlideNode = rootNode.firstChild;
currentSlideNode = firstSlideNode;
currentIndex = 1;
updateSlide(firstSlideNode);
} // end if
} // End of the function
function updateSlide(newSlideNode)
{
imagePath = newSlideNode.attributes.jpegURL;
slideText = newSlideNode.firstChild.nodeValue;
loadMovie(imagePath, targetClip);
} // End of the function
slides_xml = new XML();
slides_xml.onLoad = startSlideShow;
slides_xml.load("test.xml");
slides_xml.ignoreWhite = true;
next_btn.onRelease = function ()
{
nextSlideNode = currentSlideNode.nextSibling;
if (nextSlideNode == null)
{
}
else
{
++currentIndex;
updateSlide(nextSlideNode);
currentSlideNode = nextSlideNode;
} // end else if
};
View Replies !
View Related
Changing Default Name Of Printjob Object
I currently have an application with a working printjob function, but whenever you print it gives the printed file a default name like "Flash001"... does anyone know how to change the default name of the print object? This really only affects people printing to a PDF.
Thanks!
View Replies !
View Related
Changing Depth Of A Video Object
I've created a video object on the stage to show FLV files. Everything else is dynamically created using Actionscript.
During runtime I want to move re-parent this object and change its depth, but I can only seem to make it be at the very back or at the very front. Any ideas?
Thanks.
View Replies !
View Related
Question About Changing Object Properties
I must be stupid because I can't figure out how to change the .x value of an object for the life of me. The following is code that draws a checker board with checkers. It's very simple. (and is also not my code; was from a tutorial) The objects are all called "checker". This is confusing to me because in AS 2.0, you could not name objects with the same names. It baffles me how I'm supposed to change the x value of one checker object when they are all called "checker". Now I did try to give them different .name names with checker.name = "checker"+spaceX; (checker1, checker2, etc), but when I try to say checker1.x+=10; I get an error.
So I can't change the x values with checker.x+=10; (what I presume is the object name) or checker1.x+=10; (the instance name). I realize I CAN do this inside the function where each sprite is created, but I want to modify the x value after they've been created. Also, how does checker.x = spaceX*spaceSize + checkerOffset; know to change the .x value of the sprite it just created as opposed to one of the sprites already in existence?
ActionScript Code:
var player1Color:uint = 0x000000;
var player2Color:uint = 0xFF0000;
var spaceSize:Number = 40;
var checkerSize:Number = 30;
function drawBoard():void {
var currColor:uint;
var spaceX:int;
var spaceY:int;
// loop through x and y coordinates of board
for (spaceX = 0; spaceX < 8; spaceX++){
for (spaceY = 0; spaceY < 8; spaceY++){
currColor = (spaceX%2 != spaceY%2) ? player1Color : player2Color;
graphics.beginFill(currColor);
graphics.drawRect(spaceX*spaceSize, spaceY*spaceSize, spaceSize, spaceSize);
graphics.endFill();
}
}
}
function drawCheckerRow(rowNumber:int, playerColor:uint):void {
var spaceX:int;
var checkerOffset:Number = spaceSize/2;
var checkerRadius:Number = checkerSize/2;
var checker:Sprite;
// loop through each column in the row
// skipping every other column
for (spaceX = (rowNumber + 1)%2; spaceX < 8; spaceX += 2){
// create a new Sprite for the checker
checker = new Sprite();
checker.name = "checker"+spaceX;
checker.x = spaceX*spaceSize + checkerOffset;
checker.y = rowNumber*spaceSize + checkerOffset;
// draw checker in checker sprite's graphics
checker.graphics.lineStyle(2, player2Color);
checker.graphics.beginFill(playerColor);
checker.graphics.drawCircle(0, 0, checkerRadius);
checker.graphics.endFill();
// be sure to add it to the display list
addChild(checker);
}
}
drawBoard();
drawCheckerRow(0, player2Color);
drawCheckerRow(1, player2Color);
drawCheckerRow(2, player2Color);
drawCheckerRow(5, player1Color);
drawCheckerRow(6, player1Color);
drawCheckerRow(7, player1Color);
trace(this.getChildAt(5).name);
this.checker1.x+=10;
View Replies !
View Related
Changing Properties Of Not Yet Created Object
Hi guys,
What is the best way for creating an event listener that it will
change the properties of an dynamically attached movieclip after it has been
generated?
So basically I have two buttons the first creates and adds a movieclip to
the stage and the second one change the movieclip's position.
How do I do this without receiving an error?
the bellow code returns: (1120: Access of undefined property blocko.)
ActionScript Code:
button1.addEventListener(MouseEvent.CLICK,addMovieClip);
function addMovieClip(e:MouseEvent):void{
var blocko:block = new block();
addChild(blocko);
}
button2.addEventListener(MouseEvent.CLICK,changeProperties);
function changeProperties(e:MouseEvent):void{
blocko.x=300;
}
Thanks a lot
View Replies !
View Related
Gradually Changing The Color Of An Object
What I want to do is to transition the color of an object to a different color gradually. In other words, in frame 1 i have a light gray circle. In frame 30, I have a dark gray circle. I want to show a smooth transition from the light gray to the dark gray. Can this be done with a motion tween?
View Replies !
View Related
Dynamically Changing The Colour Of Object
I have a client that has a series of products that come in different colours and different textures. What I need to do is have picture of the product. When the user runs a mouse over the colour palette the product changes it's colour to represent the chose made by the customer fro the various choose in a colour palette. Ford Canada does this when I pick the colour of my car. I can run over red and the car will change colour to red.
Just wondering how this is done
View Replies !
View Related
|