checking instance name (character selection screen)


Kirupa Community. I am trying to make a character selection screen. So I thought the most efficient (for my skill level) was to make a single "selectionBox" class. Then I would add mulitple instances of this class with different names (not through code, just drag them and give them names). then through a mouse event listener, I could go through and check to see the instance names of the "selectionBox" class. Problem is, how could I do this I dont know how to check instance name.

EDIT: I think I'm leaning towards an array, but I have not the slightest idea how to use that......
Posted On: Thursday 3rd of January 2013 10:20:51 PM Total Views:  221
View Complete with Replies

RELATED TOPICS OF Flash / ActionScript PROGRAMMING LANGUAGE




Coloring (or erasing) an object, and checking when complete

Hi. I've got to build a kids game at the moment for my school, and I was planning to have a sort of archaeological dig, with the kids required to rub the screen (it's for a touch-screen) to "un-earth" the bones underneath. I was thinking of either erasing an overlay and checking for a hitTest between the two objects, or coloring in with a line or something. Is it possible to color something in and check when the object has been completely colored or possible to erase an overlying object and if so, can you point me in the direction of a tutorial or a quick explanation
VIEWS ON THIS POST

51

Posted on:

Thursday 25th October 2012
View Replies!

Flash checking integrity of external dynamic swf before display

hey, the title should be: insuring the integ... so i finally got my external swf loaded into my main one. as i mentioned before it(the external swf) runs xml and dynamic poster content. the problem now is that it doesnt display properly when its loaded into my main swf (i.e. it works but the first poster doesnt display automatically and a text effect is not displayed throughout the swf). i thought its a loading issue although this issue is happening offline/online. so i added a Loader class progress complete listener to trigger add child, but its still having the same problem. anyone got any ideas
VIEWS ON THIS POST

71

Posted on:

Thursday 25th October 2012
View Replies!

Flash instances in an array cannot be displayed?

There isn't any error displaying. I traced the "rectAry[1]" and it's "undefined" When I change the variable "i" inside the statement to 3 or other values, the instance will be displayed probably. Code: package { import flash.display.Sprite; public class testClass extends Sprite { private var rectAry:Array = new Array(); public function testClass():void { ... for (var i:Number; i
VIEWS ON THIS POST

90

Posted on:

Thursday 25th October 2012
View Replies!

Creating an instance of a MovieClip without a custom class

I would like to make a new instance of a MovieClip within my library from code written in my keyframe. I relise that you can do this by making a class and using the code Code: var instancename:movieclipname = new movieclipname(); and with the MovieClips class I would need to extend MovieClip and nothing else. I am unsure if you put in the name of the MovieClip or the name of the MovieClip class in the code above so feel free to correct me. But instead of doing this can I just add a MovieClip to my stage with doing this,
VIEWS ON THIS POST

67

Posted on:

Thursday 25th October 2012
View Replies!

instance names in a array?

I have some movieclips on stage each with an instance name like this: 101, 102,103,104.. etc When I click one of them, it's istance name is added in an array: Code: myArray.push(event.currentTarget.name); I've got a button on stage too and I want when this button is clicked to change the Y of all the selected movieclips: Code: function mybutton_btn(event:MouseEvent):void { this[myArray[i]].y = this[myArray[i]].y+50; } But this code is wrong. Output error is: TypeError: Error #1010: A term is undefined and has no properties. at tich1_fla::MainTimeline/mybutton_btn() How can I achieve what I want\t
VIEWS ON THIS POST

47

Posted on:

Thursday 25th October 2012
View Replies!

Constructor argument for an instance already on stage

I have a Sprite in my library that is linked to a class (lets call it SomeClass), and i put on stage in Flash, and name the instance someClass. In my Main.as i then write: var myClass:SomeClass = this.someClass; SomeClass.as has a constructor with the same name as the class, however it require an argument. How do I pass that to the class when I made an instance of it directly in Flash by dragging it to the stage (instead of the usual ... = new SomeClass(arg); ) I tried something like this: myClass.SomeClass(arg); but that gives me this error: 1061: Call to a possibly undefined method SomeClass through a reference with static type SomeClass. thanx
VIEWS ON THIS POST

69

Posted on:

Thursday 25th October 2012
View Replies!

retrieving instance name of buttons from array and change it stae

! i am newy to AS3, i have four buttons instances (of same object) on the stage (first_btn,second_btn...fourth_btn). i created an array (btnArray) and stored buttons instance name in it. After this i created an timer event to cycle through all the button for certain interval. the code is:- function timerListener(e:TimerEvent): void { while ( i
VIEWS ON THIS POST

88

Posted on:

Thursday 25th October 2012
View Replies!

use variable instead of instance name

I'm hoping this will be an easy question to answer. Basically, I'm trying to loop through my sub menu buttons to see if they're on a certain frame. My question deals with an if statement inside a for loop: if (MovieClip(root).subMenu1.currentFrame == "16") { MovieClip(root).subMenu1.gotoAndStop("out"); } Is it possible to replace the instance name (subMenu1) with a variable I tried just replacing it but that didn't work. I also tried adding plus signs around it and that didn't work either. Obviously, I'm new to actionscript. Sorry for the stupid question =S
VIEWS ON THIS POST

50

Posted on:

Thursday 25th October 2012
View Replies!

Error checking - possible to get line numbers?

Is there any way to have flash give an error line number I get errors, but it takes forever to find out where they are taking place unless I put a "trace(start function X" "trace(end function X" everywhere. Any hints / help on not just having a random error somewhere in all the files It tells me which function it hit the error, but in visual studio you could trace it back, so I can see where in the program it's being called....
VIEWS ON THIS POST

55

Posted on:

Thursday 25th October 2012
View Replies!

currentTarget Child movieclip instance name

Greetings, This my first post asking for assistance with AS3. I've been scouring the web for the past three days trying to find a solution, and I'm stumped! Here is a link to the latest version of my FLA (http://www.see-g.net/flash/header.fla). The code I am having trouble with is all the way at the bottom (Actions layer on the stage). Below the multi-line comment. Basically, I have a rotating image bar. One the first level of my file, on the stage, is a container movie clip called "imageScroll". The code that allows the images to rotate is applied to the container clip. Inside of "imageScroll", are a series of 36 images, each with their own unique instance name. On the main level, I have a block of code which first detects when the user mouses over imageScroll. Next my code attempts to dig down one level into imageScroll and find the instance name of the image the users mouse is hovering over. I want to then store that instance name in a string "_destination", then take that string and store it in a MovieClip variable "currentClip". By doing this, I can then use the variable currentClip to effect the code at the bottom, which causes the images to scale up when the user mouses over, and scale back when the user mouses out. The way I currently have my file set up, the code always returns the instance name imageScroll. I am using event.currentTarget.name to try and pull the instance name of the image. I have tried using event.target.name, but that pulls the instance name of a movie clip two levels lower then I want to go. I basically need a way to modify my code so it finds out which movie clip inside of the container imageScroll the user is mousing over. For those who would prefer to have all the code here, see below: Code: //Import required flash packages import flash.utils.*; import flash.events.Event; import flash.events.MouseEvent; import flash.ui.Mouse; import fl.transitions.Tween; import fl.transitions.TweenEvent; import fl.transitions.easing.*; //Create a new Timer object, "myTimer" //The number "10" means that the timer will tick every .01 seconds var myTimer:Timer = new Timer(10); //Variables that define the default, positive, negative, and stationary "x" direction velocities for the scrolling of the images. var xVelDef = .25; var xVelPos = 2; var xVelNeg = -2; var xVelZer = 0; //Event listener to detect when "myTimer" is initialized, which then triggers defaultScroll, //the function that causes the images to rotate at their default rate, as well as when the mouse leaves the stage. myTimer.addEventListener(TimerEvent.TIMER, defaultScroll); //Code to initialize myTimer myTimer.start(); //Function that causes the images to rotate at their default rate function defaultScroll(event:TimerEvent) { imageScroll.x += xVelDef; //if statement that causes the images to loop infinitely if (imageScroll.x > 935) { imageScroll.x = -585; } } //Function that contains the event listener to detect when the mouse leaves the stage, to resume default scrolling function Start() { stage.addEventListener(Event.MOUSE_LEAVE, resumeScroll); } //Function that resumes the default scrolling of the images //First it stops the main timer "myTimer", then starts it again, effectively resetting the timer function resumeScroll(evt:Event):void { myTimer.stop(); myTimer.start(); } //Event listener to detect when the user mouses over the left arrow button scrollLeft.addEventListener(MouseEvent.MOUSE_OVER, scrollLeftOver); //Function to execute when the user mouses over the left arrow button function scrollLeftOver(event:MouseEvent):void { //Create a new timer object, which will be tied to the new scroll rate var scrollLeftTimer:Timer = new Timer(10); //Event listener to detect when the new timer "scrollLeftTimer" is initialized scrollLeftTimer.addEventListener(TimerEvent.TIMER, timedLeftOver); //Code that stops "myTimer", effectively cancelling the default scroll function myTimer.stop(); //Code that starts that scrollLeftTimer, increasing the scroll rate of the images scrollLeftTimer.start(); //Function that causes the images to scroll to the right at an increase velocity function timedLeftOver(event:TimerEvent) { imageScroll.x = imageScroll.x + xVelPos; if (imageScroll.x > 935) { imageScroll.x = -585; } } //Event listener to detect when the mouse leaves the left scroll arrow scrollLeft.addEventListener(MouseEvent.MOUSE_OUT, scrollLeftOut); //Function that executes when the users mouse leaves the left scroll arrow function scrollLeftOut(event:MouseEvent):void { //When the scrollLeftTimer stops, the images cease to rotate scrollLeftTimer.stop(); imageScroll.x += xVelZer; if (imageScroll.x > 935) { imageScroll.x = -585; } } } //Event listener to detect when the user mouses over the right arrow button scrollRight.addEventListener(MouseEvent.MOUSE_OVER, scrollRightOver); //Function to execute when the user mouses over the right arrow button function scrollRightOver(event:MouseEvent):void { //Create a new timer object, which will be tied to the new scroll rate var scrollRightTimer:Timer = new Timer(10); //Event listener to detect when the new timer "scrollRightTimer" is initialized scrollRightTimer.addEventListener(TimerEvent.TIMER, timedRightOver); //Code that stops "myTimer", effectively cancelling the default scroll function myTimer.stop(); //Code that starts that scrollRightTimer, increasing the scroll rate of the images scrollRightTimer.start(); //Function that causes the images to scroll to the left at an increase velocity function timedRightOver(event:TimerEvent) { imageScroll.x = imageScroll.x + xVelNeg; if (imageScroll.x < -1420) { imageScroll.x = 100; } } //Event listener to detect when the mouse leaves the right scroll arrow scrollRight.addEventListener(MouseEvent.MOUSE_OUT, scrollRightOut); function scrollRightOut(event:MouseEvent):void { //When the scrollRightTimer stops, the images cease to rotate scrollRightTimer.stop(); imageScroll.x += xVelZer; if (imageScroll.x < -1420) { imageScroll.x = 100; } } } //This code executes the function which causes the images to resume scrolling when the mouse leaves the stage //Since the movie is looping on frame 1, this function is executed repeatedly. Start(); /* This block of code looks down one level in the imageScroll movieclip (Stage -> imageScroll -> target movieclip). Depending on which image the user mouses over, the instance name of that image is stored in the variable "_destination". After the function storeInstanceName has been called successfully, and the instance named has been stored, that instance name will be used in the functions "scaleImageUp" and "scaleImageDown" to apply the tween to the images/buttons. */ var _destination:String; //Event listener to detect when users mouses over container movieclip imageScroll. imageScroll.addEventListener(MouseEvent.MOUSE_OVER, storeInstanceName); //Function that reaches down one level into imageScroll, to retrieve the instance name of the image that is being moused over. function storeInstanceName(event:MouseEvent):void { _destination = event.currentTarget.name; trace(_destination); } var currentClip:MovieClip = MovieClip(_destination); //Event listeners to detect when the user rolls the mouse over and out of the image currentClip.addEventListener(MouseEvent.ROLL_OVER, scaleImageUp); currentClip.addEventListener(MouseEvent.ROLL_OUT, scaleImageDown); //Function that eases/tweens the moused over image, scaled up function scaleImageUp(event:MouseEvent):void { var xScale:Tween = new Tween(currentClip,"scaleX", Elastic.easeOut, currentClip.scaleX, 1.1, 1, true); var yScale:Tween = new Tween(currentClip,"scaleY", Elastic.easeOut, currentClip.scaleY, 1.1, 1, true); } //Function that eases/tweens the moused out image, scaled down function scaleImageDown(event:MouseEvent):void { var xScale:Tween = new Tween(currentClip,"scaleX", Elastic.easeOut, currentClip.scaleX, 1, 1, true); var yScale:Tween = new Tween(currentClip,"scaleY", Elastic.easeOut, currentClip.scaleY, 1, 1, true); }
VIEWS ON THIS POST

70

Posted on:

Thursday 25th October 2012
View Replies!

Accessing instances on second frame

I can't seem to access instances in a movie clip that aren't on the first frame of a parent movie clip even if I tell flash to go to that frame before I attempt to reference the instance in the actionscript. Actually this works in flash player 10 but not 9. I could just export for flash player 10 but I would rather know the answer than just avoid it and of course for better compatibility reasons. I've attached an fla example with source code to show the problem. I'm using CS4 and programming in classes in as3 as you will be able to see from the example. Any help from anyone who knows how to do this properly would be greatly appreciated.
VIEWS ON THIS POST

69

Posted on:

Thursday 25th October 2012
View Replies!

delete object instances

Regarding AS3, Flash Player 9: I have a strip of SimpleButton-s which on mouseover will display a Bitmap in a Sprite location along with some TextField-s whose positions are dynamically calculated based on the Bitmap.width. With the below code, I find that the memory usage (Windows Task Manager > Processes) keeps increasing on each MouseOver. Is there anything I'm doing wrong How do I force garbage collection or explicitly delete the new TextField-s Code: function onMouseOver(index:uint) { _theSprite.removeChild(_theTextField); _theSprite.removeChildAt(0); // the bitmap _theTextField = new TextField(); // ... _theSprite.addChild(_theBitmapArray[index]); _theSprite.addChild(_theTextField); }
VIEWS ON THIS POST

63

Posted on:

Thursday 25th October 2012
View Replies!

Referencing instances of an object - newbie

Im having a problem getting my head around referencing instances of an object in AS3, can somebody please help I want to be able to build a navigation and reference each navigation item separately changing each instances properties depending on rollover actions etc. I would have thought that once the name is assigned through the for loop that would stick, eg. the following code would create 3 vars called navItem, each with the name 0, 1, 2. But it seems if I trace the name outside of the for loop each is called 2. I think Im misunderstanding something really simple! Please help.
VIEWS ON THIS POST

56

Posted on:

Thursday 25th October 2012
View Replies!

basic question - naming instances dynamically

My actual file is much more complex than this, but let's just say I need a loop that creates a bunch of xml files. Don't ask why, just try and accept that it's what I need... Something like: Code: for(i=1;i xml10. I've never learned how to create instances with names that are the combination of multiple existing strings/variable/whatever. It seems like it should be possible, but is it How
VIEWS ON THIS POST

85

Posted on:

Thursday 25th October 2012
View Replies!

Dynamically called MC is called "instance 000" when traced...This is a problem.

So! I've got a website I'm working on with a very simple three button interface... First off, I've got a dynamically called Movieclip that's a child of the stage. What I'm attempting to do now, is make it so that when you click anywhere that isn't the Movieclip, it kills said Movieclip! I tried to do this by calling a function that looks at the name of the Movieclip, but for some reason, the dynamically called Movieclip is called "instance 000"... Any suggestions here's the function that calls the Movieclip. Code: function ResumeAction (e:MouseEvent):void { var ResumePane_MC:Resume_Pane = new Resume_Pane(); ResumePane_MC.x = stage.stageWidth/2; ResumePane_MC.y = stage.stageHeight/2-50; ResumePane_MC.name = "ResumeName"; stage.addChildAt (ResumePane_MC, stage.numChildren); stage.addEventListener(MouseEvent.CLICK, CheckTo Close); }
VIEWS ON THIS POST

45

Posted on:

Thursday 25th October 2012
View Replies!

How to create a mc instance?

Hi , I'm loading an external image trough this code: var richiesta:URLRequest = new URLRequest("img/foto1.jpg"); var immagine:Loader = new Loader(); immagine.load(richiesta); addChild(immagine); Now all works fine but I don't know how to use this image. If I want for exemple change the alpha of this loaded image how to do this Do i have to make a new instance of it Can you help me please
VIEWS ON THIS POST

44

Posted on:

Thursday 25th October 2012
View Replies!

About "Automatically declare stage instances"

Automatically declare stage instances... do you design with that box checked or unchecked If I uncheck it, in order to avoid conflict when I create external classes, how can I easily refer to the children of my instance For example, I have myClass.myBackground. I would like to access to myBackground (but if the box is unchecked I can't...)
VIEWS ON THIS POST

85

Posted on:

Thursday 25th October 2012
View Replies!

creating new object instance/copy in for loop?

The issue I'm having is rather for the sake of optimizing my code. While I'm still new to AS3, I guess I have troubles understanding some basic concepts. Anyway, here's the scenario: It is from a game where the user picks a crop, either apples, corn or dairy. Based on that selection, the user will be able to play a matching game with a bunch of objects moving around. Those three main objects (apple, corn, dairy) are just containers, a movieclip that holds several different subobjects, like gala apple, golden apple, etc. With for-loops, I'm looping through the main object to place the subobjects on stage. This would look like this; Code: /** * Depending on crop picked, bring the appropriate objects on stage. */ switch (_mainTimeline.cropPick) { case "Apple" : var matchObjectSilo:ApplesSilo = new ApplesSilo; matchObjectSilo.gotoAndStop(_objectToPick); matchObjectSilo.x = _CROP_SILO_X_POS + (h * _CROP_SILO_X_SPACING); matchObjectSilo.y = _CROP_SILO_Y_POS; var colorTransform:ColorTransform = matchObjectSilo.transform.colorTransform; colorTransform.color = 0xC7C7C7;// color them grey matchObjectSilo.transform.colorTransform = colorTransform; addChild(matchObjectSilo); break; case "Corn" : var matchObjectSilo:CornSilo = new CornSilo; matchObjectSilo.gotoAndStop(_objectToPick); matchObjectSilo.x = _CROP_SILO_X_POS + (h * _CROP_SILO_X_SPACING); matchObjectSilo.y = _CROP_SILO_Y_POS; var colorTransform:ColorTransform = matchObjectSilo.transform.colorTransform; colorTransform.color = 0xC7C7C7;// color them grey matchObjectSilo.transform.colorTransform = colorTransform; addChild(matchObjectSilo); break; case "Dairy" : var matchObjectSilo:DairySilo = new DairySilo; matchObjectSilo.gotoAndStop(_objectToPick); matchObjectSilo.x = _CROP_SILO_X_POS + (h * _CROP_SILO_X_SPACING); matchObjectSilo.y = _CROP_SILO_Y_POS; var colorTransform:ColorTransform = matchObjectSilo.transform.colorTransform; colorTransform.color = 0xC7C7C7;// color them grey matchObjectSilo.transform.colorTransform = colorTransform; addChild(matchObjectSilo); break; } Although this works perfectly fine, for example purposes I only posted a couple lines out of the actual things that would need to happen in each case-statement. So rather than having some 50 lines of code per statement, where only one line is really different (first one), I would like to have only that one line in the case and the for-loop separate. The thing that I don't understand now, how would I create a new (dynamic) object inside that for-loop, that would represent the one instantiated in the case-statement Here's what I've tried so far, which sorta worked but not quite; Copying. Code: switch (_mainTimeline.cropPick) { case "Apple" : var initObjectSilo:ApplesSilo = new ApplesSilo; break; case "Corn" : var initObjectSilo:CornSilo = new CornSilo; break; case "Dairy" : var initObjectSilo:DairySilo = new DairySilo; break; } for (var h:uint = 0; h < _MATCHES; h++) { var matchObjectSilo:Object = new Object(); matchObjectSilo = copy(initObjectSilo); matchObjectSilo.gotoAndStop(_objectToPick); matchObjectSilo.x = _CROP_SILO_X_POS + (h * _CROP_SILO_X_SPACING); matchObjectSilo.y = _CROP_SILO_Y_POS; var colorTransform:ColorTransform = matchObjectSilo.transform.colorTransform; colorTransform.color = 0xC7C7C7;// color them grey matchObjectSilo.transform.colorTransform = colorTransform; addChild(matchObjectSilo); } public function copy(source:Object):* { var copier:ByteArray = new ByteArray(); copier.writeObject(source); copier.position = 0; return(copier.readObject()); } This throws a compile time error, at the line where it tries to access the first property; 1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject. probably due to the fact that through the copying process, it "forgets" what kind of class/object it was before. "registerClassAlias" is supposed to take care of this but I can't use it in my case, as I can't hardcode anything in the for-loop that references the original class. Since there are three original classes (apple, corn, dairy), this has to be dynamic. Other option I tried, did work but only half way: Array. Code: switch (_mainTimeline.cropPick) { case "Apple" : var initObjectSilo:ApplesSilo = new ApplesSilo; break; case "Corn" : var initObjectSilo:CornSilo = new CornSilo; break; case "Dairy" : var initObjectSilo:DairySilo = new DairySilo; break; } for (var h:uint = 0; h < _MATCHES; h++) { var matchObjectSilo:Array = new Array(); matchObjectSilo.push(initObjectSilo); matchObjectSilo[0].gotoAndStop(_objectToPick); matchObjectSilo[0].x = _CROP_SILO_X_POS + (h * _CROP_SILO_X_SPACING); matchObjectSilo[0].y = _CROP_SILO_Y_POS; var colorTransform:ColorTransform = matchObjectSilo[0].transform.colorTransform; colorTransform.color = 0xC7C7C7;// color them grey matchObjectSilo[0].transform.colorTransform = colorTransform; addChild(matchObjectSilo[0]); } This compiles and no runtime error but it only adds one object to the stage, the one from the last loop. Despite the "new" operator, it just seems to only reference once to the original class and does not create multiple instances... Again, maybe I'm missing some basic concepts here and there is a much easier solution. I would appreciate any suggestions, on how to create a new dynamic instance of an object inside the for-loop. TIA.
VIEWS ON THIS POST

108

Posted on:

Thursday 25th October 2012
View Replies!

is there an "is instance of" property or function?

is there an "is instance of" property or function for example, i added a mouse_down event listener on the stage. On the stage, there are instances of an apple class and instances of orange class, both of which extends the Sprite class. is there some sort of property for: if (evt.target."is instance of" == apple) { trace ("you clicked an apple") } i tried if evt.target == apple, but it doesnt work.
VIEWS ON THIS POST

55

Posted on:

Thursday 25th October 2012
View Replies!

Flex Casting an instance object from an external swf

I have a custom class called GoalKeeper.as . In my external swf, i create an instance of this class like Code: var myGoalKeeper:GoalKeeper = new GoalKeeper() And the from my main swf, i just make a reference to use myGoalKeeper. Code: var rootGoalKeeper:GoalKeeper = externalSwf.myGoalKeeper; And when i run the main swf, i got the following error TypeError: Error #1034: Type Coercion failed: cannot convert game::GoalKeeper@35896381 to game.GoalKeeper. myGoalKeeper is just an instance of GoalKeeper class, what is wrong Note:I develop classes in Adobe Flex and compile my projects in Adobe Flash CS3.
VIEWS ON THIS POST

63

Posted on:

Thursday 25th October 2012
View Replies!

XML Menu (giving mc unique instance name)

Ok so I found this tutorial for building an XML menu but what it fails to do explain how to give each nav an instance name so I can bring in content or whatever. Can anyone please tell me what I need to do so that I can add an event listener to each movieclip.
VIEWS ON THIS POST

69

Posted on:

Thursday 25th October 2012
View Replies!

creating public instance in function

, i need to create some instances at run-time and need to acces them from an other function. Code: function createEnemy(enemyCount:Number){ // I will write a loop here var enemy1:enemy = new enemy("strong_enemy"); this.addChild(enemy1); //loop end } createEnemy(7); //will create 7 enemy instance trace(enemy1.currentStatus); //Variable enemy1 is not defined. trace(this.enemy1.currentStatus); //Variable enemy1 is not defined. how can i access to the public properties or public methods of enemy1 from outside of that function thank you for your answers.. , by declaring the variable outside of the function Code: var enemy1:enemy; function createEnemy(enemyCount:Number){ // I will write a loop here enemy1 = new enemy("strong_enemy"); this.addChild(enemy1); //loop end } createEnemy(7); //will create 7 enemy instance trace(enemy1.currentStatus); //Variable enemy1 is not defined. trace(this.enemy1.currentStatus); //Variable enemy1 is not defined.
VIEWS ON THIS POST

48

Posted on:

Thursday 25th October 2012
View Replies!

Update an instance position from an external class?

First post! Been searching the boards/web for a couple days now looking for an answer to the following. Apologies if this has already been answered previously. And I'm new to ActionScripting in general, hence the lengthy explanation: I have an fla with a DocumentClass. I also have two classes called Ball and Buttons. * The DocumentClass creates an instance of Button and adds it to the stage. * When clicked, the button adds an instance of Ball to the stage. (let's call it _ball) * Immediately after creating _ball, a function Go() is called from the button class (e.g., _ball.Go(); ) THE PROBLEM * I also want to Go(); function to update the position of the instance _ball, but the instance isn't recognized within the class Ball. (if I try _ball.x = 100 I get, 1119: Access of possibly undefined property ball through a reference with static type flash.display:Stage.) How would one go about doing this
VIEWS ON THIS POST

42

Posted on:

Thursday 25th October 2012
View Replies!

checking hitTest with movieclip inside movieclip

I have a game where different movieclips are loaded randomly from an array in to a movieclip call flavors and move across the stage. Flavors is then loaded into the main timeline. I'm trying to test if a movieclip called "butterscotch" is loaded into the flavors movieclip and hits another movieclip called "butterscotch_tube". If it hits the right tube, the it adds one point, if it hits the wrong tube, all points are erased. Here is the code inside Flavors: Code: var flavors:Array; var thisFlavor:MovieClip; flavors = [new creamSoda_mc(), new rootBeer_mc, new strawberry_mc, new cherry_mc, new watermelon_mc, new grape_mc, new bubblegum_mc, new butterscotch_mc, new cottonCandy_mc, new raspberry_mc, new sourApple_mc, new chocolate_mc, new mystery_mc]; thisFlavor = flavors[Math.floor(Math.random() *flavors.length)]; addChild(thisFlavor); Here's the checking in the main timeline: Code: if(flavor.thisFlavor.hitTestObject(tubes.butterscotch_tube)) { if(flavor.thisFlavor == thisFlavor[7]) { butterscotchScore ++; trace("butterscotch = " + butterscotchScore); flavor.removeEventListener(Event.ENTER_FRAME, hitTube); } else { butterscotchScore = 0; trace("butterscotch reset"); flavor.removeEventListener(Event.ENTER_FRAME, hitTube); } } The problem, I believe, is in (flavor.thisFlavor == thisFlavor[7]). thisFlavor is giving me an error, and I don't know what to put in the parenthases to get this working.
VIEWS ON THIS POST

54

Posted on:

Thursday 25th October 2012
View Replies!

triyng to get eventdispatcher trigger listener in multiple instances

hi. im migrating to as2 from as2. and im having a lot of understunding problems regarding scopes and how to refer to functions, classes, etc i used asbroadcaster in as2 to register m,ultiple listener with a single event. now, with as3 im trying to use EventDispatcher to do the same. but it doesnt work. in fact, i dont know really how does it work. in as2 i create an asbroadcaster in root then i add listeners to it from within multiple movieclips, so when the event was thrown from anywhere the listeners registered for that event where triggered. how do i acompplish that in as3 in advance
VIEWS ON THIS POST

60

Posted on:

Thursday 25th October 2012
View Replies!

how to make a instance delete it's self

ok say i wanted to add a function to a class that made it delete its self, this code checks out to be ok, but doesn't work can somebody explain to me how i would do this Code: class suicide { function suicide() { delete this; } }
VIEWS ON THIS POST

52

Posted on:

Thursday 25th October 2012
View Replies!

Use same variable in different functions?

, I have a function that includes a variable which I need to use in a different function after some effects occur. Is this possible If I try to use it it doesn't recognize it.
VIEWS ON THIS POST

49

Posted on:

Monday 29th October 2012
View Replies!

stop object from moving further when collision occurs.

As the title says: Stop object from moving further when collision occurs. Right now I'm trying to make a sliding puzzle. So far I have a block which I can click and drag around, and a few walls which are the boundaries. What I'm trying to do is make an area where the block can slide within the boundaries. So when you try to drag the block into an direction it will stop, whether you got mouse_down or mouse_up. My script so far Code: stop(); //Sliding Blocks MCBlock1.addEventListener(MouseEvent.MOUSE_DOWN, pickUp); MCBlock1.addEventListener(MouseEvent.MOUSE_UP, dropIt); function pickUp(event:MouseEvent):void { event.target.startDrag(true); } function dropIt(event:MouseEvent):void { event.target.stopDrag()} //Colision MCBlock1.addEventListener(Event.ENTER_FRAME, enter_frame); function enter_frame(event:Event):void{ if (MCBlock1.hitTestObject(MCwall1)) { dropIt(); } } Anyone have any idea how to do this Also I need to use a lot of boundaries, so if there's a way to apply this script easily to several objects, please let me know.
VIEWS ON THIS POST

54

Posted on:

Monday 29th October 2012
View Replies!

How to use ADDED_TO_STAGE event to load an external xml driven swf menu

Hi .....
VIEWS ON THIS POST

51

Posted on:

Monday 29th October 2012
View Replies!

Question on multiple click items

I am working on a project where I need the player to click on multiple items, before being able to click on a door to another room. I am pretty new to action script and flash. Can you explain how to do this for me
VIEWS ON THIS POST

41

Posted on:

Wednesday 7th November 2012
View Replies!

AS3 Game Score Problem

I am making my very first AS3 game, and though it's quite simple I'm having trouble setting up a scoring system. The concept of the game is simple. Objects appear on the screen, clicking the objects adds points. For this project I am working with 3 AS files, a Document class and two movieclip class files. I would also like to track how many objects have been added to the stage in addition to the score which should track how many objects have been clicked. Here is my Doc Class package { import flash.display.MovieClip; import flash.display.Stage; import flash.events.Event; import flash.events.TimerEvent; import flash.events.MouseEvent; import flash.utils.Timer; import flash.text.TextField; import VegeDoc.tomato; import VegeDoc.carrot; public class VegeDoc extends MovieClip { public var tims:Timer = new Timer(1500, 1); public var score_txt:TextField = new TextField; public var myScore:Number = 0; public var createTomato:Timer; public var createCarrot:Timer; public function VegeDoc() { var newTom:VegeDoc.tomato = new tomato(); stage.addChild(newTom); var newCarrot:VegeDoc.carrot = new carrot(); stage.addChild(newCarrot); createTomato = new Timer(1000); createTomato.addEventListener(TimerEvent.TIMER, sendTomato); createTomato.start(); createCarrot = new Timer(1000); createCarrot.addEventListener(TimerEvent.TIMER, sendCarrot); createCarrot.start(); tims.addEventListener(TimerEvent.TIMER_COMPLETE, sendTomato); tims.start(); } public function sendTomato(e:Event) { var t2 = new tomato(); stage.addChild(t2); } public function sendCarrot(e:Event) { var c2 = new carrot(); stage.addChild(c2); } public function onclick(e:MouseEvent):void { score_txt.text = String(myScore+10); } } } This is one movie clip class (they are both identical, except class names) package VegeDoc { import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; import flash.utils.Timer; import flash.events.TimerEvent; import flash.text.TextField; import flash.utils.getDefinitionByName; import flash.display.DisplayObject; import flash.display.DisplayObjectContainer; public class tomato extends MovieClip { public var speed:Number; public var timmy:Timer = new Timer(50,0); public var xSpeed: Number = -7; public var ySpeed: Number = -3; public var score_txt:TextField = new TextField; public var myScore:Number = 0; public function tomato(){ this.x = Math.random(); this.y = Math.random()*800; speed = Math.random()*10 + 5; addEventListener(Event.ENTER_FRAME, moveTomato, false, 1, true); addEventListener(MouseEvent.CLICK, clickTomato, false, 2, true); addEventListener(MouseEvent.CLICK, onclick, false, 0, true); } public function moveTomato(e:Event):void{ var mc:MovieClip = MovieClip(e.target); mc.x += mc.speed; if(mc.x < -2000 || mc.x > (this.stage.stageWidth + 12000)){ mc.removeEventListener(Event.ENTER_FRAME, moveTomato); mc.removeEventListener(MouseEvent.CLICK, clickTomato); mc.stage.removeChild(mc); } } public function clickTomato(e:MouseEvent):void{ var mc:MovieClip = MovieClip(e.target); mc.removeEventListener(Event.ENTER_FRAME, moveTomato); mc.removeEventListener(MouseEvent.CLICK, clickTomato); mc.parent.removeChild(mc); } public function onclick(e:MouseEvent):void { score_txt.text = String(myScore+=10); trace (String(myScore)); } } }
VIEWS ON THIS POST

32

Posted on:

Saturday 10th November 2012
View Replies!

Need Help

Hi all, I have an problem with this project, the client wants me to design exact same as in picture, so please through some easy process to do this, its for car racing game environment which i am going to do with adobe flash cs5.
VIEWS ON THIS POST

34

Posted on:

Saturday 10th November 2012
View Replies!

Need Help

Hi all, I have an problem with this project, the client wants me to design exact same as in picture, so please through some easy process to do this, its for car racing game environment which i am going to do with adobe flash cs5.
VIEWS ON THIS POST

23

Posted on:

Thursday 15th November 2012
View Replies!

Need A Script

i learning..
VIEWS ON THIS POST

64

Posted on:

Friday 30th November 2012
View Replies!

embedded video complete help?

Hi Guys, i'm trying to figure out how to get an embedded video I have to when it completes start a new function. For example I have running.flv embedded in a movieclip timeline called p2. And I want to have actionscript know when the video ends and start a new movieclip. Appreciate any help!
VIEWS ON THIS POST

36

Posted on:

Friday 28th December 2012
View Replies!

Flash How to change SelectionColor in TLFTextFielfd ?

How to change SelectionColor in TLFTextFielfd created with var txtTest:TLFTextFielfd = new TLFTextFielfd(); syntax , Here i want to change the selected text bg color.
VIEWS ON THIS POST

31

Posted on:

Friday 28th December 2012
View Replies!

ReferenceError: Error #1065: Variable TLFTextField is not defined.

I've just switched from CS5 to CS5.5. In Cs5 my game worked fine, and everything was happy but not in CS5.5 it's telling me that there I've got an undefined TLFTextField. The text itself is inside a dynamically added movie clip, and it's value is changed in the main timeline.... The code in the main timeline: "ZombieHouseArray[txtSet].Hp_txt.text = ZombieHouseArray[txtSet].Hp;" like i said, this did work fine but no it wont work at all.
VIEWS ON THIS POST

77

Posted on:

Friday 28th December 2012
View Replies!

Flash Sending multiple emails.

Hoping you could help me with this. I have as3 in a fla and I have a php script on my server sending the mail after being sent a variable from flash. I have no difficulty getting this working but the problem is I need it to send to two adresses, one which the user types in a text box with id email_txt and then I wanted to add my email as well so it sent both to the adress the user types in and to mine var note:String; var variables:URLVariables = new URLVariables(); var mailAddress:URLRequest = new URLRequest("http://www.email.com/email.php"); send_btn.addEventListener(MouseEvent.CLICK, onSubmit); function onSubmit(e:Event):void { variables.sEmail = email_txt.text + "email@gmail.com"; variables.sMessage = note_txt.text; variables.sName = ""; variables.sSend = "Razor"; note = date_txt.text + "\n" + namep_txt.text +"\n" + user_txt.text +"\n" +hotel_txt.text +"\n" +note_txt.text; variables.sMessage = note; variables.sSubject = "Rezidor job Form." mailAddress.data = variables; mailAddress.method = URLRequestMethod.POST; sendToURL(mailAddress); } send_btn.addEventListener(MouseEvent.CLICK, onPrint) ------------- ----------- I've tried this and that and nothing seems to work. I know the problem is somewhere with this line: variables.sEmail = email_txt.text + "email@gmail.com"; I tried changing it to = variables.sEmail = email_txt.text + "email@gmail.com"; and variables.sEmail = "email_txt.text + email@gmail.com"; even tried variables.sEmail = email_txt.text + &email@gmail.com; I have also tried changing the php. Made a new variable called email2 and introduced it to the php. Nothing seems to work.
VIEWS ON THIS POST

36

Posted on:

Friday 28th December 2012
View Replies!

help please error 1180 and potentially null objects, ect..

Using this code I get these dreaded errors: Scene 1, Layer 'Actions', Frame 61, Line 5 1180: Call to a possibly undefined method Worm. and Scene 1, Layer 'Actions', Frame 61, Line 6 1180: Call to a possibly undefined method Killer. I have the feeling I need to make classes and have separate .as files for worm and killer but am not sure if I can solve this problem without this as I am not sure how to make classes(I have very basic as3 understanding and am not trying to be lazy) Is there something someone can suggest that I 1) learn how to make classes for these and a reference for info on that or 2) I don't need to and its just something simple I am missing import flash.display.MovieClip; import flash.events.Event; // instantiate Killer and Worm instances from the library var worm:MovieClip = new Worm(); var killer:MovieClip = new Killer(); // position worm worm.x = 200; worm.y = -50; // not sure where killer is supposed to be killer.x = stage.stageWidth/2 - killer.width/2; killer.y = stage.stageHeight/2 - killer.height/2; // add killer and worm to the displaylist addChild(worm); addChild(killer); var speed:Number = 5; var movement:Number = 5; addEventListener(Event.ENTER_FRAME, descent); function descent(e:Event):void { worm.y += speed; // worm exit test if ( worm.y >= 635 ) { removeEventListener(Event.ENTER_FRAME, descent); } // mouseX test if ( mouseX > worm.x + 5 ) { worm.x += movement; } else if (mouseX < worm.x - 5) { worm.x -= movement; } else { worm.x = mouseX; } // worm collision test if ( worm.hitTestObject(killer) ) { removeChild(worm); removeEventListener(Event.ENTER_FRAME, descent); gotoAndPlay(237); } } It is a game where the parachutes(falls down) and the player moves the mouse and the worm avoids hitting the fish(killer) and lands on the island winning the game. I had no problems getting the worm to listen to me and what it says in the code until I placed the hitTest in then I tried this approach of naming them movieclips...before my problem was they were null.
VIEWS ON THIS POST

32

Posted on:

Saturday 29th December 2012
View Replies!

remove listeners with an array

I'm trying to remove all the event listeners from nextBtn. the names of all the possable callback functions are stored in mdpArray. I want to use the for loop to remove all the listeners from nextBtn. the error message says cannot convert "mdp1_1" to Function How can i make this work. Thank you for your help. Code: var mdpArray:Array = ["mdp1_1","mdp1_2","mdp1_3","mdp1_4","mdp1_5"]; private function clearEvents(nextBtn):void{ var _nextBtn = nextBtn; for(var i:Number = 0; i
VIEWS ON THIS POST

29

Posted on:

Sunday 30th December 2012
View Replies!

Flash picture strips panning

Hi , I have been trying to create an image gallery, where more strips of pictures are put one above the other (one strip representing one subgallery). The functionality is simple. When user clicks and holds mouse button, he controls the strip (moving from left to right) to see the complete strip and all pictures, that the strip contains. I was able to find and tweak the code to use one gallery strip (content_mc in the code below). But now I am struggling to have two or more picture strips one above the other to work. Any help is appreciated. I am a beginner. Code: import flash.events.MouseEvent; import flash.geom.Point; import flash.events.Event; import flash.geom.Rectangle; import flash.display.MovieClip; var destination:Point=new Point(); var dragging:Boolean=false; var speed:Number=5; var offset:Point=new Point(); // offset var bounds:Rectangle=new Rectangle(0,0,stage.stageWidth,stage.stageHeight); //content bounds content_mc.addEventListener(MouseEvent.MOUSE_DOWN,startDragging); content_mc.addEventListener(MouseEvent.MOUSE_UP,stopDragging); content_mc.addEventListener(Event.ENTER_FRAME,followMouse); function startDragging(e:MouseEvent):void{ offset.x=content_mc.mouseX*content_mc.scaleX; // record offset for object dragging dragging=true; } function stopDragging(e:MouseEvent):void{ dragging=false; } function followMouse(e:Event):void{ if(dragging){ destination.x=mouseX; } content_mc.x-=(content_mc.x-(destination.x-offset.x))/speed; // apply offset if(content_mc.x>bounds.left){ //boundaries (called in var bounds) content_mc.x=bounds.left; } if(content_mc.x
VIEWS ON THIS POST

26

Posted on:

Sunday 30th December 2012
View Replies!

Same Callback Function on different ty of EventHandler

I have 2 event listener in my document class. One is for a TimerEvent.TIMER and another is for VideoEvent.COMPLETE. Now my question is can i assign a single callback function for both of them Code: vdo.addEventListener(VideoEvent.COMPLETE, completeVideo); myTimer.addEventListener(TimerEvent.TIMER, completeVideo); In both listeners the callback function completeVideo is same. This function's definition is like this: Code: private function completeVideo(e:Event) { } Its working. But is this good Any side effect or memory load
VIEWS ON THIS POST

37

Posted on:

Sunday 30th December 2012
View Replies!

Flash Timing movie clips at different time intervals

, It feels like it's been ages since I've worked in Action Script (dissapointingly the demand just isn't there for me) and I'm really, really rusty. I'm working on a Flash banner, and one particular part has 5 movie clips. I want each movie clip to fire off at separate intervals(i set it at 300 miliseconds per clip) Here is the code I have written that works for two clips: Code: //Animate each icon var timer:Timer = new Timer(300, 1);//create the timer timer.addEventListener(TimerEvent.TIMER, doNextTween); timer.start(); var tween_mc:Tween = new Tween(mc_bb, "y", Strong.easeOut, 100, 1, 1, true); function doNextTween(e:TimerEvent):void{ var tween_mm:Tween = new Tween(mc_mm, "y", Strong.easeOut, 100, 1, 1, true); timer.removeEventListener(TimerEvent.TIMER, doNextTween); } This works great for the first two tweens, but I can't figure out how to apply this to all five. I'm sure the answer is obvious, and I will be rather emabarassed when I find out the answer.
VIEWS ON THIS POST

28

Posted on:

Sunday 30th December 2012
View Replies!