AS3 - set mcs to current label - actionscript-3

I've got 3 dolls : sitting, jumping, and running.
& I have dresses. All of my dresses models are designed in 3 positions : sitting, jumping & running.
dolls_btns contains 3 btns to choose the doll, who starts with undies, their name are : sitting_with_undies, jumping_with_undies, running_with_undies.
(Undies are removed when a dress is applied).
dolls_mc contains :
on frame 1 : nothing
on frame 2 : sitting_with_undies, // label : sitting_with_undies
on Frame 3 : sitting_naked, // label : sitting_naked
on frame 4 : jumping_with_undies, // label : jumping_with_undies
on frame 5 : jumping_naked, // label : jumping_naked
on frame 6 : running_with_undies, // label : running_with_undies
on frame 7: running_naked // label : running_naked
dresses_btns contains buttons which allow to choose the color of the dress
dresses_for_sitting contains:
on frame 1: empty frame,
on frame 2: 1 pink dress // label : pink_dress
on frame 3: 1 red dress // label : red_dress
on frame 4 : 1 green dress // label : green_dress
and more dresses
dresses_for_jumping contains:
on frame 1: empty frame,
on frame 2: 1 pink dress // label : pink_dress
on frame 3: 1 red dress // label : red_dress
on frame 4 : 1 green dress // label : green_dress
and more dresses
dresses_for_running contains:
on frame 1: empty frame,
on frame 2: 1 pink dress // label : pink_dress
on frame 3: 1 red dress // label : red_dress
on frame 4 : 1 green dress // label : green_dress
and more dresses
Lets say I choose the sitting doll & then apply her a pink dress.
Next, if i click on dresses_btns.green_dress, as the doll is already set to sitting, the green sitting-shaped dress will come up.
I can apply any other dress color, by clicking on my dresses_btns, as the position is set. // ok
But now if i click on running, the sitting-shaped dress doesn't disappear, as clicking on a doll only switches between dolls positions, but doesn't apply the correct shaped-dress.
So what i'm lookig for is :
1) I choose the sitting position & 2) apply it a pink dress. // ok, done
3) Then, when clicking on jumping > I want to remove the sitting pink dress, & replace it by jumping pink dress .
As I have many dresses, many positions, many hair styles, & clothes, & accessories, I need an easy way to manage all of my items, according to the last clicked position.
// here we are in dolls_btns
var myDolls = [sitting_with_undies, jumping_with_undies, running_with_undies];
for each ( var doll in myDolls)
{
doll.addEventListener(MouseEvent.CLICK, onPositionClick);
doll.buttonMode=true;
}
function onPositionClick(e:MouseEvent):void
{
MovieClip(parent).dolls_mc.gotoAndStop(e.target.name); // places the chosen doll's position on stage
if ( e.target == myDolls[2] ) /// lets say I've clicked on running
{
// what I'm trying to achieve :
if ( MovieClip(parent).dresses_for_sitting.currentLabel=="pink_dress")
{ MovieClip(parent).dresses_for_sitting.gotoAndStop(1) // empty frame
MovieClip(parent).dresses_for_running.gotoAndStop("pink_dress");
// That works, but I'd like to use dresses_for_sitting.currentLabel instead of naming each label one by one, as I have too many cases, clothes, hair colors, & hair styles, accessories, etc
}
}
}
I've been searching the web for over 12 hours & tryied many solutions, in vain.
I think currentLabel should do the trick but I lack of knowledge to complete my functions.
Anticipate thanks

if ( MovieClip(parent).dresses_for_sitting.currentLabel=="pink_dress")
{
MovieClip(parent).dresses_for_running.gotoAndStop(dresses_for_sitting.currentLabel);
MovieClip(parent).dresses_for_sitting.gotoAndStop(1) // empty frame
// That works, but I'd like to use dresses_for_sitting.currentLabel instead of naming each label one by one, as I have too many cases, clothes, hair colors, & hair styles, accessories, etc
}
Set dresses_for_running to the dresses_for_sitting current frame before setting
dresses_for_sitting to the first frame as I showed above.
Right now you are resetting it before assigning dressing_for_running to the dresses_for_sitting frame, so it resets as well

Related

how to show symbols on top of LilyPond scores?

Santa offered a toy keyboard to my 4-year-old. He enjoys the provided scores, but I'd like to add some songs that we sing together and that are not included in the basic set. Every Key has a symbol (circle, triangle, square) and a color (blue, yellow, purple, red, orange) that is displayed on top of the music score, to help him figure out which keys to press.
I'm not a musician, but I do have a basic understanding on how to write music scores. I've never used lilypond, but I'm a developer and I know latex.
I tried searching for a way to add extra symbols, but I'm not sure this is feasible.
You can draw theses symbols by using some of the various graphics commands found on this page:
https://lilypond.org/doc/v2.24/Documentation/notation/graphic
Store these as markup macros at the top of the LilyPond file, and then call them in the score at the appropriate places.
\version "2.24.0"
blueTriangle = \markup {
\left-align
\with-color "blue"
\triangle ##t
}
orangeCircle = \markup {
\left-align
\with-color "orange"
\draw-circle #1 #0 ##t
}
purpleCircle = \markup {
\left-align
\with-color "purple"
\draw-circle #1 #0 ##t
}
greenSquare = \markup {
\left-align
\with-color "green"
\filled-box #'(0 . 2) #'(0 . 2) #0
}
\new Staff {
g4^\blueTriangle
d'^\orangeCircle
b'^\purpleCircle
f''^\greenSquare
}
This will be a bit tedious if you are placing a symbol above every note. But if you know Scheme you can probably devise a function that reads the note letters and octaves and places the correct symbol in automatically.

Save data in dynamical text in another frame while working on current frame as3

I am working on Flash actionscript 3 to create a quiz using combobox. I used the following code.
stop();
box1.addEventListener(Event.CHANGE, changeHandler);
\\box1 is combobox 1
function changeHandler(event:Event):void
{
if (box1.selectedIndex == 1)
\\there are two values in combobox with index 1 and 2
{
name1.text = "1) Wrong";
\\name1 is the dynamical text box
}
else if (box1.selectedIndex == 2)
{
name1.text = "1) Right";
}
else
{
name1.text = "";
}
}
I put the dynamical text box on frame 4 while the combobox is in frame 2
I created two comboboxes. when I select an option from combobox 1, I get an error like this: Error #1009: Cannot access a property or method of a null object reference.
So I extended the dynamical text layer from frame 2 to frame 4. But after running the program, the result is shown only in frame 2 immediately after selecting the value from combobox 1; so that the result is displayed before selecting combobox 2.
What I need is to save the result in frame 4 and it is displayed only when I go to that frame using next buttons.
Any help would be appreciated. I am beginner in Flash actionscript.(I prefer using interface than coding).
Your output should be displayed if all conditions are met. So the code might look something like this
if (condition1 && condition2 && condition3 && condition4)
{
// do stuff
}

CCPhysicsjoint not keeping the 2 bodies intact

I want to add a particle body(say Fire) before another physics body(the arrow).
So, i am using the spring joint to keep them joined with stiffness around 20000, but still its starting the correct way and the particle-body swings away form the arrow. Here's my code:
fire part
CCParticleSystem *explosion= [CCParticleSystem particleWithFile:#"bomb.plist"];
explosion.position = ccpAdd(projectilePos, ccp(16,0));
explosion.physicsBody.mass=1.0;
explosion.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:16.0 andCenter:explosion.anchorPointInPoints];
explosion.physicsBody.type=CCPhysicsBodyTypeDynamic;
explosion.physicsBody.affectedByGravity=FALSE;
explosion.physicsBody.allowsRotation=FALSE; //so that fire flames go upwards only, and not rotate
[physicsWorld addChild:explosion];
explosion.physicsBody.collisionMask=#[];
arrow part
CCSprite *tempSprite;
tempSprite = [CCSprite spriteWithImageNamed:#"arrow3#2x.png"];
[tempSprite setScale:0.05];
[tempSprite setScaleY:0.15];
tempSprite.rotation=rotation;
tempSprite.position=dummyBow.position;
tempSprite.name=[NSString stringWithFormat:#"%#,%d",[lifeOfSprite[1] objectForKey:#"name"],[[lifeOfSprite[1] objectForKey:#"life"] intValue]];
tempSprite.physicsBody = [CCPhysicsBody bodyWithRect:(CGRect){CGPointZero, tempSprite.contentSize} cornerRadius:0]; // 1
tempSprite.physicsBody.collisionGroup = #"playerGroup";
tempSprite.physicsBody.collisionType = #"projectileCollision";
[physicsWorld addChild:tempSprite z:0];
projectile.physicsBody.mass=100;
now the joint part
[CCPhysicsJoint connectedSpringJointWithBodyA:playerBomb.physicsBody bodyB:projectile.physicsBody anchorA:ccp(1,1) anchorB:ccp(600,0) restLength:0.f stiffness:20000.f damping:60.f];
(debugDraw)
the fire should come at the front, but swings back from front by spring effect
Can anyone tell where's the problem?
Thanks in advance.

Navigating through an array of game objects without showing duplicate objects

I'm working on a game, in my game the user acquires weapons (cupcakes) throughout the levels. I have a button that the player clicks to change to the next cupcake (weapons acquired are stored in an array).
Here's my problem: if the player acquires 2 yellow cupcakes, 1 red cupcake, and 2 blue cupcakes, how do I navigate through the array without showing the same cupcake twice?
My button looks as if it's not changing weapons, when in code it is, it's going to the next element in the array but it's the same weapon [yellow cupcake, yellow cupcake, red cupcake, blue cupcake, blue cupcake].
public function CupcakeChangeButton(e: MouseEvent) {
cakeButtonCounter++;
//Make sure the cakeButtonCounter never exceeds the amount of
//elements in array
if (cakeButtonCounter >= CupcakesArray.length - 1) {
cakeButtonCounter = 0;
}
//NOTE: may need function called "cupcake count", this function should
//be called at the beginning of THIS function and in the constructor function
//Should count the amount of cupcakes and maybe set wasSeen Elements to No
/*
The switch statment makes its decisions based on the type of cupcake
is the current elment. The current element is represented by
"cakeButtonCounter" (CupcakesArray[cakeButtonCounter])
The if statements decides if the cupcake has been seen already.
If it hasnt been seen, it sets the button's text box to show how many of
those kind of cupcakes are left.
After the amount of cupcakes of that type is shown in the text box,
the "unshift" method is used to place "yes" in the first element, of it's
own Array type, WITHIN THE WAS SEEN ARRAY.......confusing!!!!!!
Example:
wasSeen.PinkCupcake.unshift("yes") = wasSeen.PinkCupcake[0] == "yes"
This is done so that we can keep track of what cupcakes has been seen
already
When the game is initialized the was seen elements are set to "no". So when
it's set to "yes", after being seen, The initial value,"no", is placed in the
next element. It's no longer needed, so we use the "splice" method to delete it
and HOPEFULLY, remove it from memory
The "else" block of code takes place if the cupcake has already been seen.
It increments the cakeButtonCounter so that the button will display the next
cupcake in the array, that has NOT been seen
After all decisions are made,(which cupcakes are next and which cupakes have
been seen)
Update the button's face by displaying the next cupcake that hasnt been seen
(button goes to and stop and next element)
NOTE: The ACTUAL case will be the dynamic var cupcake type (the NAME not the actual
cupcake)
*/
switch (CupcakesArray[cakeButtonCounter]) {
case "PinkCupcake":
if (wasSeen.PinkCupcake[0] == "no") {
CupcakeNavigationBox.countBox.text = "x" + PinkCupcakeCount;
wasSeen.PinkCupcake[0] == "yes";
trace("element change? " + wasSeen.PinkCupcake[0]);
} else {
cakeButtonCounter++;
trace("if yes...its starting that way " + wasSeen.PinkCupcake[0]);
}
break;
case "YellowCupcake":
if (wasSeen.YellowCupcake[0] == "no") {
CupcakeNavigationBox.countBox.text = "x" + YellowCupcakeCount;
wasSeen.YellowCupcake[0] == "yes";
} else {
cakeButtonCounter++;
}
break;
case "GreenCupcake":
if (wasSeen.GreenCupcake[0] == "no") {
CupcakeNavigationBox.countBox.text = "x" + GreenCupcakeCount;
wasSeen.GreenCupcake[0] == "yes";
} else {
cakeButtonCounter++;
}
break;
case "PurpleCupcake":
if (wasSeen.PurpleCupcake[0] == "no") {
CupcakeNavigationBox.countBox.text = "x" + PurpleCupcakeCount;
wasSeen.PurpleCupcake[0] == "yes";
} else {
cakeButtonCounter++;
}
break;
}
CupcakeNavigationBox.buttonFace.gotoAndStop(CupcakesArray[cakeButtonCounter]);
changeCupcake();
}
You should instead store available types of weapons in the array from where you choose the weapon type. Also, that array should contain ints, because apparently your cupcakes are spent on fire/action, thus you will have the ammo storage array at your disposal. If you need unlocked array, by all means make another array. (Make sure there's a default weapon, though, or else cake selection function can go into an infinite loop)
var cupcakesAmmo:Array=[0,0,0,0,0,0,0]; // as many as you have types of cupcakes
var cupcakesTypes:Array=[RedCupcake,YellowCupcake,PinkCupcake,GreenCupcake,BlueCupcake,PurpleCupcake,BlackCupcake];
// let's say we have seven cupcakes
var currentCupcake:int; // the selected weapon
function cupcakeChangeButton(e: MouseEvent) {
// first check if we actually have anything to change to
var weHave:int=0; // how many different cupcakes we have
var i:int;
for (i=0;i<cupcakesAmmo.length;i++) if (cupcakesAmmo[i]>0) weHave++;
if (weHave<2) return; // hehe, we either have no cupcakes or just one type of em
// otherwise let's change
do { // we have to do this at least once
currentCupcake++;
if (currentCupcake==cupcakesAmmo.length) currentCupcake=0; // change type
} while (cupcakesAmmo[currentCupcake]==0); // change until we find the type with nonzero ammo
// okay, type selected, let's get proper display
CupcakeNavigationBox.countBox.text = "x" + cupcakesAmmo[currentCupcake];
// see, no switch is needed! Just get the data off your array :)
// TODO change the displayed cupcake too (I don't see where you do this)
}

as3 Making a scrolling Movieclip

I was wondering if its possible to create a scrolling MC after children have been added inside of it thats extends the parents boundaries. For instance I have a grade book UI mc, and inside of that I have a movie clip called student names. Inside student names I have code to add another movie clip that will dynamically show a students name from a db. The for loop repeats and another mc will be added below it. However, after they are all added, the children still show outside of the parent mc (student names). is it possible to make sure all the children inside student names stay inside the parent, and I can scroll down to see the rest of the children. (pretty much like a data grid) The children being added are light and dark shaded boxes containing the student names to be easily read.
function addStudentList():void
{
for (var i:int = 0; i < currentArr.length; i++)
{
if (i % 2 != 0)
{
var darkShade:mc_darkShade = new mc_darkShade;
darkShade.name = "darkShade";
darkShade.x = xCoordinate;
darkShade.y = yCoordinate;
darkShade.studentName.text = currentArr[i].lastname + ", " + currentArr[i].firstname;
studentArr.push(darkShade);
addChild(darkShade);
yCoordinate += 33.10;
}else
{
var lightShade:mc_lightShade = new mc_lightShade;
lightShade.name = "lightShade";
lightShade.x = xCoordinate;
lightShade.y = yCoordinate;
lightShade.studentName.text = currentArr[i].lastname + ", " + currentArr[i].firstname;
studentArr.push(lightShade);
addChild(lightShade);
yCoordinate += 33.10;
}
}
}
Thank you!
Josh
I found a reusable, touch scrollable list of items suitable for AIR apps targeted at iOS devices. You can download the source code and also one example here, if you want to see one example, before you download, check it here
The files use Greensocks ThrowProps so you will need to download as well.