Event Based On Movieclip Instance
Hello!
Bit new to actionscript and need som help from a expert.
I'm trying to add events for specific movieclips. I have a few buttons on top of a toolbar. The buttons should have unique events and the toolbar should also have unique events. If I add an event on the toolbar, even though I press the buttons the toolbar get trigged..I don't want this. If a button is pressed the toolbar event should not be trigged, only the button. But if I click the toolbox - where ther isnt a button in front of the toolbox should be trigged.
I guess this is a really simple thing to fix. Please help
/Adrian
ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 10-05-2006, 11:05 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Controlling A Movieclip Based On Instance Name
Hello Everyone,
I have got a simple movie clip which runs a short animation when clicked upon. The movie clip contains a series flags and each has an name. The movie has been replicated a number of times on the main stage, and each has been given its own instance name.
When i currently click on the movie clip all of the instances are running. What would be the best way to display just one clip at a time, based on calling its individual instance name and setting is to go to a specific flag in the moveclip.
Any help would be appreciated.
Kind regards
Timbronze
Can I Control A MovieClip Animation Based On A NetStream Event?
First off, here is the website I'm working on:
http://www.littlefenris.com/RAMPSI/
What I am trying to do is get the animation of the audio levels (red bars next to the power switch) to only happen while a video is actually playing (videos are in the video gallery section). I have the animation done and I can easily get it to start and stop based on pressing the play and stop buttons, but since they start and pause the video you would get instances where the video isn't playing but the audio levels would be animated, which I don't want.
Here is an example of the code in the play button (using NetConnection and NetStream to play the videos):
Code:
play_btn.onPress = function() {
playSound.start();
infoText_txt.text = "PLAY";
my_ns.pause(spotToPlay);
};
The only way I can think to make it work exactly as I want it is to have Flash look to see if the video is actually playing or not and I can't figure out how to do this or if its even possible using the NetStream command I am using to start and stop the videos.
Any help is much appreciated.
Instance Names...changing...or Addressing Txt Field Instance Based On Instance Of Mc
i'm creating a mail form, that has a text effect which displays the type of info to be entered in each input box. To create this effect, i had to assign the variable name txt to the input boxes as well as the instance name txtBox. each of these text fields is contained within a movieclip, each with a unique instance name. what i need to do, is somehow assign a value/variable to each text field to pass to PHP to generate an email. I have always used components for contact forms so i'm not sure how to make the switch, AND.. the script i use for my contact form is an EXTERNAL AS file. (i use a customized version of a contact form from www.actionscript-toolbox.com [which apparently is no longer Flash related site])
ok.. this is hard to explain..... so bear with me....
If my original mail form component instance names were: tiName, tiEmail, tiSubject and taMsg (ti for textInput and ta for textArea)
and my current instance names for the mc's which CONTAIN the input boxes (with txtBox textfield instance inside them) are: name_txt, email_txt, subject_txt & comments_txt...
how would i pass/convert the users input text in each movieclip's txtBox, into the original instance name for my mail form so i can continue to use the form/PHP i have been using??
OR....
how do i take the values input by the user in each txtBox (i.e name_txt.txtBox.insertedTextFromUser or name_txt.txt, email_txt.txtBox.insertedTextFromUser or email_txt.txt) and send them to a new PHP script to send mail??
please keep in mind i am PHP retarded... hence why i re-use the same form over and over..
thanks in advance for any help. it's greatly appreciated...
if you're confused about my problem, please let me know... i'm having a difficult time explaining....
How To Make The Event Based Block Into Procedure Based
i'd like to do something like this
var a = getXML("xmlfile.xml");
However, the xml component is event based. I only get data when onLoad is fired.
How to wrap this kind of event based function into my custom function?
Accessing Movieclip Instance Within Another Movieclip Instance
Accessing library movieclip instance within another library movieclip instance issues.
I have a movieclip in the Library called menuBar. In the menuBar mc I added two buttons. I want to be able to click on each button to play a video for each corresponding button. When I mouse over the button the pointer turns into the hand, suggesting it recognizes it as a button. But I'm unable to access the button (menuBar.button1 in AS2) in my code, I'm using AS3. Any help would be much appreciated. Thank you for your time.
Creating Usable Variable Based On Instance Name
Right
I have been away from Flash for a while, but even going through my old stuff I haven't found what I am looking for... here it goes
I need to create a usable variable based on the movie clip instance name.
I manage to create the name:.
code:
var variable_name = String(this._name)+"_value";
which will generate my desired variable name (eg. myMCName_value).
The question is:
How do I use this generated name as a variable name?
I need to assign a value to it as in
code: myMCName_value = 1;
but I don't want to actually have that command line in the script. because the whole thing won't know that this variable will exist until it is created.
Did I made myself clear enough?
Passing XML-based Hyperlink Into A Button Instance
Hi,
I'm currently trying to load specific XML data as a hyperlink into a button,
the hyperlink is saved in the xml-file, and called upon by "childURL",
now if I assign this function to the child_mc, which is formed into a menu dynamically within an instance named emptyMC, it will give me the link:
Code:
btnLink.onRelease = function() {
getURL(childURL, "_blank");
};
problem is I want to assign the link, when the child_mc-movieclip is clicked, to a button named 'linkbutton' on the main stage
- which will then load the page assigned in the xml-file when clicked.
How would I load this data inside the button on stage?
All codes I tried just open my browser and link to nowhere.
Event Based Upon Rotation?
Hello.
Is there a clean way to run differing functions based upon the rotation value of a movieclip? I have a menu with 119 drinks on it, all the drinks are shown as strings of text pointing outward from the circumference of a circle. The resulting circle of wines can be rotated, and the user will be provided with additional info as each drink becomes horizontal to the screen.
Is it a case of having an array containing all the relevant info, an event listener listening for the rotation value, and a switch pointing to the correct movieclip to display? Or am I thinking this through ar$e-backwards as usual!
A.
Mouse Event, Event.target Vs Movieclip Name
Hi -
Can anyone help me with a mouse event issue, i'm truly baffled. There's a timer event that loads 4 movieclips (named 'serviceType'), each containing an instance of 2 objects (named 'btn' and 'thumbs'). When clicking on the MC (servicetype) it triggers a mouse event. I'm trying to reference child 'thumbs' of the serviceType MC but in the mouse event function, event.target traces no children, but serviceType traces the 2 children. BUT serviceType only refers to the last instance of serviceType that was loaded in the timer event. Why wouldn't event.target work??
Here's the code, and thanks for the help!!
ActionScript Code:
function loadServices(event:TimerEvent):void {
count = event.target.currentCount -1;
serviceType = new MovieClip;
addChild(serviceType);
btn = new Btn(serviceList, count);
thumbs = new ThumbContainer(count);
serviceType.addChild(btn);
serviceType.addChild(thumbs);
serviceType.addEventListener(MouseEvent.CLICK,loadThumbs);
}
function loadThumbs (event:MouseEvent):void {
trace(serviceType.numChildren); /// Displays 2 (but refers to the last instance loaded)
trace(event.target.numChildren);// Displays 0, why??
}
Tracking Event Based Test
Hi:
I am trying to build a test such that we have the user run through several picks and clicks and based on his input we grade the user at the end. So I have some buttons which are supposed to be tracked when clicked etc.. can someone please help me wiith this code..
Thanks
Schedule Based Event Handler
Looking for some advice:
* I need to load in a schedule of events (xml).
* These events are precisely timed (down to a tenth of a second).
* The events (like, attach movie to main screen) need to last for a very precise amount of time (again, within a tenth of a second).
So, it would run like so:
Schedule gets loaded that says:
* "show banana for 15.5 seconds @ 2 min and 32 seconds after the movie started, then remove the banana."
* "show apple for 12 seconds @ 4 min and 12 seconds after the movie started, then remove the apple."
and so on... like 100 of them.
So, what's the best way to handle this? It seems like I'll certainly have to use "setInterval" in there somewhere - but I'm looking for the cleanest and most accurate way to do this.
To complicate things further - my scene is rather computationally intensive (even on the f8 player) and timing accuracy seems to be a weak spot for flash in this kind of situation.
Suggestions?
Change Var Based On Mouse Event
Hi All I hope some one can help with this. I'm new to AS3 so I'm not even sure if I'm taking the right approach. Basically what I want to accomplish is submenu rollover navigation. I can get the main menu to show up and work fine. If I set the var button = 1, 2 ect it pulls the correct section of my XML to display the submenu, but I can't seem to set that var on a mouse_over so when I roll over a different section it changes var.
Hope that makes sense. I also attached my files
Thanks in advance.
PHP Code:
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("navigation2.xml"));
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
ParseNavigation(xmlData);
ParseMainMenu(xmlData);
}
var mainMenuContainer:Sprite = new Sprite();
var test:int = 1;
var button:int = test;
var submenuContainer:Sprite = new Sprite();
submenuContainer.x = 142;
//trace(mainMenuContainer.miItem);
function ParseMainMenu(mainMenuContent:XML):void {
trace("XML Output");
trace("------------------------");
trace(mainMenuContent.MainMenu.@name);
trace(mainMenuContent.MainMenu.@level);
var MenuList:XMLList = mainMenuContent.MainMenu;
var buttonCount:int = 0
for each(var prop in MenuList) {
var miItem:mainMenu = new mainMenu();
miItem.tLabel.text = prop.@name;
miItem.name = prop.@level;
miItem.url = prop.@variable;
miItem.y = (miItem.height * buttonCount);
mainMenuContainer.addChild(miItem);
buttonCount++;
}
}
function ParseNavigation(navInput:XML):void {
/*trace("XML Output");
trace("------------------------");
trace(navInput.Category.subCat.@name);
trace(navInput.Category.subCat.@level);
trace(subLevel);*/
var subMenuList:XMLList = navInput.MainMenu.subMenu;//.(@sublevel == button);
trace(button);
var buttonCount:int = 0
for each(var prop in subMenuList) {
if (prop.@sublevel == button) {
var miItem:MenuItem = new MenuItem();
miItem.tLabel.text = prop.@name;
miItem.name = prop.@name;
miItem.url = prop.@variable;
miItem.y = (miItem.height * buttonCount);
submenuContainer.addChild(miItem);
buttonCount++;
}
}
}
addChild(mainMenuContainer);
stop();
MenuItem Code As Follows
PHP Code:
var url:String;
this.addEventListener(MouseEvent.MOUSE_UP, gotoURLHandler);
this.addEventListener(MouseEvent.MOUSE_OVER, displaySubmenuHandler);
this.addEventListener(MouseEvent.MOUSE_OUT, removeSubmenuHandler);
function gotoURLHandler(evt:MouseEvent):void {
navigateToURL(new URLRequest(url));
}
function displaySubmenuHandler(event:MouseEvent):void {
var myRoot:MovieClip = root as MovieClip;
var myParent:MovieClip = this.parent as MovieClip;
var button = event.target.name;
trace(button);
this.addChild(myRoot.submenuContainer); // this works for pull the menus in the correct place
}
function removeSubmenuHandler(evt:MouseEvent):void {
var myRoot:MovieClip = root as MovieClip;
//this.removeChild(myRoot.submenuContainer);
}
this.buttonMode = true;
tLabel.mouseEnabled = false;
Any Ideas? Event Based Pr. Wierdness
http://www.nebulouscore.com/examples...on_class2b.swf
I am working on some event based stuffed which is kinda new to me so maybe someone knows why the bug in this thing happens. The fla is there to if you want to see the code.
When you click the pointer springs to the mc you clicked and calls the next function for all the mc's between the two you click... giving it a sort of traveling effect. BUT it has a tendency to almost randomly highlight an mc as though one of the events got lost on the heap.
That text at the bottom is a sema4 I put in to keep track of the queued tweens and it always returns to 0.
If nothing else, the fit-to-n thing I have going on with the Build_mc_Collection() might be worth borrowing.
Anyway.. I hope you guys might have a clue why this wierdness happens.
The Problem With Event Based Programming
Hi gang,
I have two thread running, the second of which is not getting any response.
ranger class
any ideas? event based pr. wierdness
So.. here is the deal. I am loosing faith in event based programming in flash for reasons mentioned in the second thread. I have no idea what is going on here. The reason I actionscript code the way I do is that I like being in controll and know exactly when something is supposed to execute.
Event based programming has one "flaw" that I find myself searching for workarounds in order to "fit the model". That flaw is that you only get one shot at handling an event. That event certainly can trigger other events but again, this causes one to venture into creative solution to make a series of events happen in "just such a way".
In the above threads, I you can see an example of this thingy I am trying to make where clicking on a menu item makes all the items in between highlight then unhighlight using a tween as it travels the menu items between the previously selected item and the one you just clicked on. (thats a mouthful).
Ideally I would like to call a Next(), which triggers the indexChanged, which starts a tween, calls Next, which triggers the indexChanged.. until the index of Next is equal. BUT! since this event based programming and I have "only shot" I have to get the job done in that one spot.
here is a code snippet
Code:
mcCollection.cursor.setDirection(1);
for(var i=previ;i<newi;i++)
{
mcCollection.cursor.Next(); // triggers onIndexChanged
}
By slamming the "event system" with Next functions, something wierd happens where I suspect the order of events being fired is not the order in which they were called.
In fact, the trace shows:
out:colMC1
in:colMC1
out:colMC2
in:colMC2
out:colMC3
in:colMC3
out:colMC4
in:colMC4
out:colMC5
... sequential throughout until here
out:colMC11
in:colMC11
out:colMC12
in:colMC12
out:colMC13
out:colMC12
in:colMC12
you can see at the end that 12 gets an "extra call".. as though it fired twice. This is just one example of some of the output I have seen from the trace.
anyway.. I just wanted to *****. It's a hobby i guess. Regardless.. event based code is fine for
"when I click this do this"
but gets quircky when
"when I click this, do all this (each of the "all this" is "fire another event").
that sounds muddy I know.. but.. anyway. Frustrated.
Changing Up Event Based On Variable
Is there a way that I can change the color of a button based on a variable in the Flash movie?
I've created the button, I have created Over and Hit events for it, but the Up event needs to be dynamic. So there are one of three options, it could be, say, red, blue or transparent. By default I have it set to transparent, and that works great, but I couldn't find a way to change the color, on load, based on a variable (say if x = 1 then I want the button to be red).
This is bound for a data integration app, but I just need to make sure that it will do what I need it to first.
Thanks in advance for any help. If you can provide code or links to tutorials that might help I would really aprpeciate it.
Brent
Play Sound Based On Instance Or Library Name Without First Filling Brackets?
On my main stage I have rows of regular buttons I made from static text - titles of mp3 files in my root folder, - and each of them has an instance name identical to the mp3 file, but without the .mp3 extension -
I have a fantastic code that enables me to both play an mp3 and simultaneously push it into an array by clicking any of those buttons on the main stage - it uses the instance name to play and then add the mp3 into the array. Here's the code:
var PlayArray = new Sound();
stop();
//keeps me from having to duplicate button code
var a = [this.Sound01, this.Sound02, this.Sound03];
for (i in a) {
mc2 = a[i];
mc2.onPress = function() {
myLoadedSound = new Sound();
myLoadedSound.loadSound(this._name+".mp3", true);
//pushes mp3 into array
MyArray.push(this._name+".mp3");
};
}
This code works perfectly - but the problem is that I've got thousands of mp3 files - and using this method I have to have every mp3 listed between the brackets [] in line 4 - and if I'm on say frame 3, I have to have this same code on frame 3, but with whatever mp3 buttons are on that frame's main stage listed in the brackets in that frame's actionscript - so even though I no longer duplicate code on individual buttons to play mp3s, I'm now running into duplicate code on frames - I'd like to have a master code that will work independent of what frame I'm on -
BUT that's not all that important - the real reason for my post - I'd like to adapt the code so it will play an mp3 based on the name of the instance or library name as it already does, BUT not have to list them all in the brackets - just ANY button anywhere in the swf if its pushed flash tries to play an mp3 using either its instance name or library name - without having to look in the brackets to see if its a legit mp3 button.
I know this probably sounds crazy and/or impossible... Maybe just have one thing in the brackets like loading a line from a text file that has all the mp3s in it ready to be accessed??
Various Event Handlers In Same Instance
How can I invoke various event handlers for the same instance in the timeline?
For example you can use:
ActionScript Code:
on (releaseOutside, release, dragOut) {
trace("button");
}
But this only works if the AS is in the instance as a mouse event and not in the timeline.
What I have now is this:
ActionScript Code:
button.onReleaseOutside = function() {
trace("button");
};
button.onRelease = function() {
trace("button");
};
button.onDragOut = function() {
trace("button");
};
But surelly there is a better way of doing this. Right?
Flash Event Based On Computer Clock
Hi.
Is there a way I can get my flash movie to play a different message based on the computers clock?
Good Morning
Good Afternoon
Good Evening
That kind of an idea.
I've seen this question before in forums but can't find the actionscript for it again. I hate that.
Thanx in advance.
Triggering An Event Based On XML <element> Contents.
Hey Gurus:
I am (slowly) learning to use XML with ActionScript 3.0 and have come across something I haven't been able to figure out on my own.
I have two buttons on the stage.
The red button is “button1”.
The orange button is “button2”.
My AS looks like this:
ActionScript Code:
//XML
var myXML:XML = <inventory>
<slot1>red_square</slot1>
<slot2>orange_circle</slot2>
</inventory>;
//FUNCTIONS
/*creates a function called addslot
that adds a <slot3> child after <slot2>*/
function addslot() {
var newSlot:XML = <slot3>green_triangle</slot3>;
myXML.insertChildAfter(myXML.slot2[0], newSlot);
}
/*creates a function called button1click
that executes addslot(), traces the XML,
then traces the contents of <slot3>*/
function button1click(Event:MouseEvent):void {
addslot();
trace(myXML);
trace(myXML.slot3.text());
}
/*creates a function called sniff that
I want to execute a trace event based
on the contents of <slot3>*/
function sniff() {
if (myXML.slot3.text()=="green_triangle") {
trace("slot3 has a green_triangle in it!");
}
}
//BUTTON LISTENERS
/*adds listeners to both buttons and calls the functions.*/
button1.addEventListener(MouseEvent.CLICK, button1click);
button2.addEventListener(MouseEvent.CLICK, sniff);
M problem is in the function “sniff”. I can't figure out the syntax needed to evaluate the contents of <slot3> and pop a trace based on its contents.
For some effin' reason, I can't attach a ZIP of my source. But, if someone could point me toward a tutorial or give me some sound advice, that'd be stellar.
Thanks,
Andrew444
AS2 Event Based Sound Class (SoundExtended)
I did this a while ago, but I guess I've been digging though my old AS2 to give anyone who needs it a little boost A while ago, ahh... well maybe not too long ago.
I made it because it always p@#$ed me off that the sound object was so crappy in flash. Countless steps to make the sound do what you want in a way a normal person would think of to control a sound. So I added many many new properties and methods, all of which are built over top the original sound object. I kept most of the old methods as well. But now all methods, including getters and setters, fire events, to make controlling the sound a heck of a lot easier. Now muting doesn't just turn the volume down ... well essentially it still does, but I took care of the memory variables in the class. So no more remembering the last volume, or the last play position, etc.,etc... it's all already taken care of in the methods of the class.
A good way to think of this is the Sound controller. But I made this before I ever heard of Model-View-Controller
So...
Let me know what you think, I don't think I have ever really shown this to anyone before. This was actually my first stab at an AS2 class, period.
When you test the source file I should have everything trace to test the events, and the class sould also be commented fairly well.
The example here:
http://www.jimisaacs.com/test/SoundExtended/
The source here:
http://www.jimisaacs.com/test/SoundE...ndExtended.zip
By the way, there's a song in that source file. I'm trusting everyone not to use it for copyright infringement
Actual Time Based Event Idealogy:::
Dear Kings of flash,
I have an idea and need to bring it to life.......
Depending on the time I need to load different flash movies into the main layout. Any ideas or suggestions on how this can be achieved.......??? the brainstorming will greatly help me cause I have a major headache trieng to figure out.......
Cheers
DJ Subandrio
(((((((0)))))))
Dispatching Instance Event From Class.
i need to dispatch an event to an instance of my class.
right now i am just doing the following.
in my class
Code:
function myClass(){
//do a bunch of stuff
onVarsLoaded();
}
public function onVarsLoaded():Void{
return;
}
and on my instance
Code:
var mycl:myClass = new myClass();
mycl.onVarsLoaded = function(){
//do stuff here.
}
this works, but im sure its not the correct way to do things.
whats the best way to do this?
Problem Getting Object Instance Name From Event
If I use the following example code :
function test():void
{
var img:Image = new Image;
img.name = "Tree";
img.source = "tree.jpg";
theCanvas.addChild(img);
img.addEventListener(MouseEvent.CLICK, moveImage);
}
private function moveImage(event:MouseEvent):void
{
trace(event.target.name);
}
the trace output returns something like "FlexLoader9" instead of "Tree" when I click on the image.
Any suggestions on how I can retrieve the object instance name in the event routine? (The above code SHOULD work according to the online docs).
Problem Getting Object Instance Name From Event
I posted this in Flash General Discussion but it's probably more appropriate here.
If I use the following example code (in Flex):
function test():void
{
var img:Image = new Image;
img.name = "Tree";
img.source = "tree.jpg";
theCanvas.addChild(img);
img.addEventListener(MouseEvent.CLICK, moveImage);
}
private function moveImage(event:MouseEvent):void
{
trace(event.target.name);
}
the trace output returns something like "FlexLoader9" instead of "Tree" when I click on the image.
Any suggestions on how I can retrieve the object instance name in the event routine? (The above code SHOULD work according to the online docs).
Mark this message as the answer.
Making CUSTOM Functions For Event-based Prog
I understand how to make listeners and use them with existing eventhandlers. Like say using..
Code:
mybutton.onPress=function(){
blah;
}
button.addListener(mybutton);
BUT-
is there a way i can specify the EVENT for a non-established new object? (by that I mean...it's not a button, or text, or key etc.)
I can say "when mybutton is pressed then fire off the event. BUT - Can I say, " Listen for when movieclip1 turns blue ? - then fire off the event? "
thanks...I'm just curious about all the things flash can do.
XML Menu Instance Names And On Click Event
I've been trying to add some necessary details to hga77's XML menu and I've run into some interesting problems.
1) All the dynamically created instances are assigned numbers for names. Problem is, AS won't let you target an object/instance called "menu.4.arrow" (For example: "_root.menu.4.arrow._visible = false;" You've got to use a string and not just a number for the instance name. If I try to change hga77's code to use something like "item"+i to create names, the menus break. I haven't been able to figure out why this is so. I could use some help changing the created instance names to a string with number attached.
2) I've been trying to figure out some way to have an arrow appear when I click on a menu item. Right now, it works when you click on a top level menu item that contains no submenu, but if you click on the item "perspective" (which contains a submenu), no arrow appears. and I haven't figured out how to get the arrow to attach to the submenu items either. Another approach would be to add an arrow inside the attached menu clip and control the visibility of the arrow, but due to problem #1 above, I can't target the arrow instance.
Thanks for your help - files can be found here:
http://www.tornedgedesign.com/_test/2level_menu.zip
Event Handler Calls Instance Member
Hello!
I want an event handler function in my class to be able to use the private variables of the class. The following attempt however returns "undefined":
ActionScript Code:
class Example {
private var someNumber:Number
...
public function doSth () {
someClip.onRelease = function () {
trace(someNumber) // returns undefined
}
}
}
I found I can do this by adding a new variable inside the function:
ActionScript Code:
public function doSth () {
var theSameNumber = someNumber
someClip.onRelease = function () {
trace(theSameNumber) // returns the value of someNumber
}
}
The problem is I don't know if this is the standart way of doing this. I need to use a lot of instance members in an event handler function and I want to do it the best way. I hope you can help me.
Thanks!
Reaching For A MovieClip From Another One & Creating An Instance Of A MovieClip
Hello everyone,
I am new to this forum, and I have to say that I find the help and support pretty active here. It's great!
I just started playing around with ActionScript 3, and I am encountering a few obstacles. I did some coding with AS2, but it seems like what I am trying to obtain is done differently now. and I am having difficulties figuring it out by myself. So here are my two questions:
1) I created a movieClip BlueSquare that I put in my library, and I want to create an instance of it when a button is pressed, and then be able to place it on stage at a precise location, and change it's properties. How can I create an instance with a name? Is there an equivalent to the former attachMovie() ? (And while we are at it, how can I then delete that instance?)
2) I am having a major difficulty changing the properties of a movieClip located in another branch of the 'object hierarchy'. Let's say I am in MovieClip11 (where the order could be Stage>MovieClip1>MovieClip11), and I want to change the alpha of MovieClip22 (where the order could be Stage>MovieClip2>MovieClip22). I understood that there are no global variables anymore, but when I try to use the 'parent' and 'root' functions to get to the alpha of that MovieClip22, I am told that I am accessing an undefined property through a reference with static type Class...
thank you for your help, I hope that I was clear in stating my issues.
Daedalus005
Mouse Event Triggers For Movieclip Inside Movieclip (can It Be Done?)
'canvas' is a large movieclip I am using to put other movieclips 'in' so I can move around and zoom everything at once. Like a coffee table with pictures on it.
I am loading up two images below with variables named map01 and map02. They overlap.
Code:
var map01:MovieClip = canvas.createEmptyMovieClip("map01", canvas.getNextHighestDepth());
map01.loadMovie("http://imagelocation1.jpg");
map01._x=-1000;
map01._y=39;
var map02:MovieClip = canvas.createEmptyMovieClip("map02", canvas.getNextHighestDepth());
map02.loadMovie("http://imagelocation2.jpg");
map02._x=-1000;
map02._y=130;
map01.onRelease = function () {
this.swapDepths(map02);
}
I would like to be able to click one of the images inside canvas and have it jump to the top. In this case, just a simple swap with map02 would be fine, I can manage the depths.
I have put a breakpoint right on the swapdepths line and debugged, and the function never gets called. Probably because it is the onrelease is for 'canvas', not any of the sibling movieclips that flash is looking for.
'canvas' has an onRelease that triggers a stopdrag and a onpress that triggers a startdrag. Removing these two triggers still does not allow any triggers for map01 or map02 to trigger though.
Any suggestions?
Is there some way to setup some logic on a canvas.onRelease function that can easily check to see if the clicked region is on an movieclip inside the canvas?
Associating Event.currentTarget Back To It's Class Instance?
I'm not sure I even labelled this correctly, but here's my problem.
I have five instances of object "Category", of which each in turn create instances of object "Tab".
the 5 instances of category, when created, are pushed to an array, which is sitting inside a class named "ButtonGroup" - ButtonGroup exists so I can addEventListeners to the Tabs from one central place which allows me to modify all the tabs in one place when a button gets pressed instead of setting up Broadcasters for every tab instance.
The event listener has been put upon Category Object>Tab Object> tabElement:MovieClip, ala
Code:
theTab.tab.tabElement.addEventListener(MouseEvent.MOUSE_UP, tabClicked);
Withing tabClicked function, I have:
Code:
selectedTab = event.currentTarget;
Hence, selectedTab is the tab I just clicked on. However, herein lies my problem. If I try to discover that tabs "Tab" instance, I can't, because the event.currentTarget.parent would be the stage...not the Tab object instance it is associated with!
How can I find what Tab instance it is associated with??
Here my class files - if they help.
HomeFlash.as
Code:
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class HomeFlash extends MovieClip {
//public var category:Array = new Array();
public var category:Array;
public var buttonGroup:ButtonGroup;
//Constructor
public function HomeFlash() {
trace("im in your constructor, tracing all your code");
buttonGroup = new ButtonGroup();
//category = buttonGroup.getCategories();
//add the all the buttons into the array.
addContents();
//Because "Hosting" is just one word, I need to move tab one into middle
//Ideally, I should be checking all tabs for text length and positioning them appropriately
tab1.button.tabText.y = 10;
}
//Adds each orb into the array
public function addContent(cItem:Category):void {
//add to teh animation handler
//category.push(cItem);
buttonGroup.addCategory(cItem);
}
//Declare all the information to go into the array
private function addContents():void {
addContent(new Category(tab1,"HOSTING", new hosting()));
addContent(new Category(tab2,"WEB" + "
" + "DESIGN", new web_design()));
addContent(new Category(tab3,"WEB" + "
" + "DEVELOPMENT", new web_dev()));
addContent(new Category(tab4,"VOIP" + "
" + "SERVICES", new voip_services()));
addContent(new Category(tab5,"NETWORK" + "
" + "SERVICES", new network_services()));
}
}
}
Category.as
Code:
package {
/*Importing neccesary classes*/
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.events.Event;
import flash.events.MouseEvent;
/* Orb Class*/
public class Category {
private var _tabElement:theTab;
private var _tabLabel:String;
private var _tabIcon:MovieClip;
private var _tab:Tab;
//Costructor
public function Category(tabElement:theTab, tabLabel:String, tabIcon:MovieClip) {
this._tabElement = tabElement;
this._tabLabel = tabLabel;
this._tabIcon = tabIcon;
//Creates a new instance of tab
_tab = new Tab(_tabElement, _tabLabel, _tabIcon);
}
//Getter functions
//Allow these functions to be called outside of this class but not be written over.
public function get tabElement():MovieClip { return _tabElement; }
public function get tabLabel():String { return _tabLabel; }
public function get tabIcon():MovieClip { return _tabIcon; }
public function get tab():Tab { return _tab; }
}
}
Tab.as
Code:
package {
/*Importing neccesary classes*/
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.events.Event;
import flash.events.MouseEvent;
/* Tab Class*/
public class Tab {
private var _tabElement:MovieClip;
private var tabLabel:String;
private var tabIcon:MovieClip;
private var tabActive:Boolean = false;
public var tabClickTime:Number = 50;
public var tabClickTimer:Timer;
public var clip:MovieClip;
public var category:Category;
//Costructor
public function Tab(tabElement:MovieClip, tabLabel:String, tabIcon:MovieClip) {
//Just store some variables
this._tabElement = tabElement;
this.tabLabel = tabLabel;
this.tabIcon = tabIcon;
this.clip = this._tabElement;
//Call function to add content onto each tab
populateTab(this.tabElement, this.tabLabel, this.tabIcon);
}
public function populateTab(_tabElement:MovieClip, tabLabel:String, tabIcon:MovieClip){
//Set the text on each tab
_tabElement.button.tabText.text = tabLabel;
//Add the icon onto each tab
_tabElement.button.addChild(tabIcon);
//Setting position and transparency of the icon on each tab
tabIcon.alpha = 0.4;
tabIcon.x = 8;
tabIcon.y = (39 - tabIcon.height)/2;
}
public function turnOff(){
tabElement.onTab.visible = false;
}
public function turnOn(){
tabElement.onTab.visible = true;
}
public function get tabElement():MovieClip { return _tabElement; }
}
}
And finally, ButtonGroup.as
Code:
package {
/*Importing neccesary classes*/
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.events.Event;
import flash.events.MouseEvent;
public class ButtonGroup {
public var tabs:Array = new Array();
public var selectedTab;
public function ButtonGroup() {
}
public function addCategory(theTab:Category):void {
tabs.push(theTab.tab);
//trace(tab);
trace(theTab.tab);
theTab.tab.tabElement.addEventListener(MouseEvent.MOUSE_UP, tabClicked);
}
public function tabClicked(ev:MouseEvent):void {
//loop through tabs:Array and turn all tabs "off"
for each (var tab:Tab in tabs) {
tab.turnOff(); //turn off function?? tab.visible = false;?
}
//set the newly selected tab
selectedTab = ev.currentTarget; //tab that triggered event
//turn it on, 'selected' references the tab that was just pressed
//selectedTab.turnOn(); //dont know what your function is? tab.visible = true;?
}
public function get getCategories():Array { return tabs; }
}
}
Finding A Movieclip Instance Name From Within The Movieclip
I know it is possible to get the id of a movieclip from within side of a movieclip, so that you can use actionscript to find the instance name of the movieclip you are in.
does anyone know the code that will be able to call this?
Cheers
Adam
Help On Removing A Named Instance Movieclip Inside A Named Instanced Movieclip
Hi Guys
I wonder if anybody can help me with my lack of actionscript 3 knowledge.
I have created 9 movieclips with a for next loop and they are given an instance name of frame(1-9). in the same loop i add another movieclip instanced with the names of pic(1-9) so in actionscript 2 its frame1.pic1...frame2.pic2....etc
So if i wanted to remove pic5 from the stage how would i go about it.
BTW the movieclips are are from the library.
with actionscript 3 i can type:-
removeChild(getChildByName("frame5"))
and that deletes the frame and the pic but i want to keep the frame. How can i only remove the pic5
thanks for looking and helping
The Dr
Actions Based On MovieClip Frame
I am trying to set up a script where a button on the main timeline targets a clip, but depending on the current frame of the clip's timeline, it will trigger to a different area on the movieclip timeline.
something like this:
tell target "animationclip"
if currentframe==1
goto and play 10
if currentframe==10
goto and play 25
Anyone have any ideas?
Thanks.
Changing Value Of Variable Based On Movieclip
I'm a newbie struggling to figure out how to write this script. I have several variables in a movie that will contain numerical values.
These values will change based on which of several random movieclips is loaded into a target.
Would I put actions in the target mc to determine which random mc is loaded into the target and then set the variables accordingly? Such as:
if the target contains mc1
then set myVariable = 5
else
if the target contains mc2
then set myVariable = 6
end if
I just can't figure out the syntax
Does anyone have an example of something like this I could see?
Thanks
Duplicating A Movieclip Based On An Array
Hi guys, I am using mdm zinc to create an application that gets the folder and file names of a certain directory then duplicates a movie clip for each file. The problem does not seem to be from mdm, because I am able to trace out each of the file names in my loop, but when I go to duplicate the movieclip it seems to only do a a couple of each. Im sure my problem is something stupid and obvious, but I havent been able to find it. Here is my code, thanks guys.
Code:
var linksArray = new Array();
linksArray = mdm.FileSystem.getFolderList("files");
var numberOfLinks = linksArray.length;
var totalLinks = numberOfLinks - 1;
for (i = 0; i <= totalLinks; i++)
{
_root["listArray" + i] = mdm.FileSystem.getFileList("files/" + linksArray[i], "*.swf");
var numOfSubLinks = _root["listArray" + i].length;
var totalSubLinks = numOfSubLinks - 1;
currentArray = _root["listArray" + i];
for (j = 0; j <= totalSubLinks; j++)
{
duplicateMovieClip("checkbox_mc", "checkbox" + j, j);
_root["checkbox" + j]._x = 5;
_root["checkbox" + j]._y = 5 + j * _root["checkbox" + j]._height;
_root["checkbox" + j].thisLabel = currentArray[j];
_root["checkbox" + j].category = linksArray[i];
mdm.Dialogs.prompt(currentArray[j]);
}
}
Movieclip Size Based On Position
Hi,
I have created a game where you can drag characters onto a background to make a scene.
What i would like to be able to do is make it so the movieclip being dragged changes size based on is position on the background.
for simplicity sake, the higher up on the background the character, the smaller it gets (to give the illusion of distance and proportion)
Thanks
Movieclip Position Based On Variables
My flash movie connects to a PHP file which sends results from a database separated by comma's. ie: 5,47,1825,
I want flash to place a copy of the movieclip on to the stage based on the figures above. The movie clip is called "takensquare". The calculation for the placement of the movieclip is quite complex but I can do that myself. For the sake of this thread I'll simplify it to the following:
Does anyone how would I make the x position of the movieclip match the results in php file?
ie: if php file outputs 5,47,1825, then I would want flash to generate 3 copies of the movieclip with the x position on 5 for the first, 47 for the second and 1825 for the third.
Any help appreciated
[CS3] Resizing A Movieclip Based On Xml Values
Hi everyone,
I'm about to start creating an xml based image gallery for my portfolio and I'm trying to find out what aspects of actionscript I need to read up on to accomplish a particular effect.
I plan to have a movieclip containing a solid colour in the background of my gallery which upon a thumbnail being clicked smoothly resizes to the dimensions of the related image before the image appears.
From what I've read so far I think I can get my head around the rest of the galleries functions, but I can't find any resources that will show me how to acheive this kind of outcome.
Any tips on areas of actionscript I should look into would be greatly appreciated.
Trigger MovieClip Based On Position
I have a tweening movie clip symbol (Object_1) that moves from left to right across the screen.
I have multiple instances of Object_2 (also a movie clip symbol) scattered on the same horizontal line (at different X-positions).
I want the Object_2 instances to be triggered individually when Object_1 approaches (i.e. Object_1._x = Object_2._x
Does anyone have some words of wisdom?
Image Animation Based Movieclip
Hi,
i develop one flash site maintain with backend,i get the images from backend to movieclip,any idea to give some animation for the movieclip.images from backend only.
Loading A Movieclip Based On The Time Of Day
Is there a way to load a MC based on an internal clock (or if that's too complicated, a digital clock based on the Digital Clock tutorial)? I also read up on the Loading Random MC tutorial, which is helpful but rather than it being random is there a way to set it so that the MC loads, for instance, everyday at noon? And it would keep this MC generated for 24 hrs until the next one that loads 24 hrs later.
Play Movieclip Based On XML Data?
Hey all,
I was wondering if somebody could help me. I wondered how to set up a flash movie that read an xml doc and depending on the value of a variable, opened a movieclip or not. so if the xml doc had a variable "cool" that had a value of "on", flash would do something like...
if (variable read from xml) is "on"
loadmovie("")
I just don't know how to set up the movie. Any tips? thanks!
MovieClip Moving Based On _x Of Another Clip?
Hi all,
I have an input text field that is in a movie clip called TXT. I have another clip in a layer under the first clip called CONTENT. I have buttons that control the position of the CONTENT clip. Id like to make it so that when CONTENT moves, TXT moves with it.
I thought I could just do this code on the TXT clip:
ActionScript Code:
onClipEvent(load){
x=TXT._x
}
onClipEvent (enterFrame){
x=CONTENT._x
}
but that obviously didnt work
Any thoughts?
Moving A Movieclip Based On Xml Data
I am trying to move a movieclip based on the number of nodes in the xml. In other words I want it to only move based on the number of "name" attributes that are within the xml. I am trying to create a dynamic portfolio and I can't seem to get it to move correctly. I have included below a sample of the xml and actionscript.
Code:
<?xml version="1.0"?>
<select>
<option name="TJ Photography" value="./gallery/pdf/tj.pdf" desc="./gallery/txt/tj.txt" pic="./gallery/preview/tj.jpg"></option>
<option name="TJ Photography" value="./gallery/pdf/tj.pdf" desc="./gallery/txt/tj.txt" pic="./gallery/preview/tj.jpg"></option>
<option name="TJ Photography" value="./gallery/pdf/tj.pdf" desc="./gallery/txt/tj.txt" pic="./gallery/preview/tj.jpg"></option>
<option name="TJ Photography" value="./gallery/pdf/tj.pdf" desc="./gallery/txt/tj.txt" pic="./gallery/preview/tj.jpg"></option>
</select>
Code:
importXML = new XML();
importXML.ignoreWhite = true;
importXML.onLoad = function(success) {
if (success) {
var xmlContent = this.firstChild;
//trace(this.firstChild.childNodes.length);
menuContent = new Array();
for (var i = 0; i<this.firstChild.childNodes.length; i++) {
nextEntry = xmlContent.childNodes[i];
menuContent[i] = [nextEntry.attributes.name, nextEntry.attributes.value, nextEntry.attributes.desc, nextEntry.attributes.pic];
}
//trace(menuContent);
menuLength = menuContent.length;
elementspacer = 1;
var menuItem, yPosition = 200;
var menuItem, xPosition = 140;
createEmptyMovieClip("clipContainer", 1);
for (var i = 0; i<menuLength; i++) {
clipContainer.attachMovie("element", "menuItem"+i, i);
thisClip = clipContainer["menuItem"+i];
thisClip.menuName = menuContent[i][0];
thisClip.destination = menuContent[i][1];
thisClip.description = menuContent[i][2];
thisClip.image = menuContent[i][3];
thisClip._y = yPosition;
thisClip._x = xPosition;
yPosition += Math.floor(thisClip._height+elementspacer);
createEmptyMovieClip("maskContainer", 2);
maskContainer.attachMovie("mask", "newMask"+i, i);
maskContainer._x = 75;
maskContainer._y = 200;
clipContainer.setMask(maskContainer);
//////////////////////////////////////////////////
clipContainer.onEnterFrame = function() {
if (scrollUp == true) {
clipContainer._y += xmlContent.firstChild.attributes.name;
} else if (scrollDown == true) {
clipContainer._y -= xmlContent.firstChild.attributes.name;
}
};
//////////////////////////////////////////////////
scrollerUp.onPress = function() {
scrollDown = true;
};
scrollerUp.onReleaseOutside = function() {
scrollDown = false;
};
scrollerUp.onRelease = function() {
scrollDown = false;
};
scrollerDown.onPress = function() {
scrollUp = true;
};
scrollerDown.onReleaseOutside = function() {
scrollUp = false;
};
scrollerDown.onRelease = function() {
scrollUp = false;
};
//////////////////////////////////////////////////
}
} else {
trace("Error loading xml");
}
};
Get Instance Name Of A Movieclip
If i have 2 movieclips on my stage and one is an instance of Triangle called Triangle1 and the other is an instance of Square called Square1 how do i loop through all the movieclips on the stage and trace their instance types?
So far i have this...
for(var name in _root){
trace(typeof(_root[name]))
}
the problem is that this only returns "movieclip" and not "Triangle" or "Square".
Is what im trying to do even possible?
|