Instance Name & String-problem
Hi again,
This is probably a silly syntax mistake, but I can't figure it out:
This works :
Code: Bimg= function(targetMC){ trace("targetMC: " +targetMC)
//here is the problem: var OrigStr:String = "_level0.mc1.thumb.holder" trace("OrigStr:" +OrigStr) // end problem var charstart:Number = OrigStr.indexOf("mc") var charend:Number = OrigStr.indexOf(".thumb") var amount:Number = charend - charstart var endResult:String = OrigStr.substring(charstart, charend) trace("result: "+ endResult) } this returns:
Code: targetMC: _level0.mc1.thumb.holder OrigStr:_level0.mc1.thumb.holder result: mc1 But this won't:
Code: Bimg= function(targetMC){ trace("targetMC: " +targetMC) // replaced the following line: var OrigStr:String = targetMC trace("OrigStr:" +OrigStr) var charstart:Number = OrigStr.indexOf("mc") var charend:Number = OrigStr.indexOf(".thumb") var amount:Number = charend - charstart var endResult:String = OrigStr.substring(charstart, charend) trace("result: "+ endResult) } returns:
Code: targetMC: _level0.mc1.thumb.holder OrigStr:_level0.mc1.thumb.holder result: undefined First I thoughed I could solve it by replacing that line for : var OrigStr:String = targetMC.toString but that doesn't help either.
Anyone?
Thanks, again,
Papermouse
FlashKit > Flash Help > Flash ActionScript
Posted on: 12-22-2004, 10:28 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
String Method From Instance Name
I'm having trouble with this(to make it quicker I'll just write here the necessary info):
I have a variable called currentURL.
this variable containes the instance name of a movieclip(in this case it's home).
I want to write a string with the instance name WITHOUT THE INITIAL _LEVEL0 PATH ELEMENT.
As I try to make a string from the variable with:
currentURLstring = new String(currentURL);
The string returnes:
_level0.home
I then try to slice it in many ways, let's say with substr:
currentURLstring.substr(7);
In theory the function showld produce a string like this:
home
...instead I still get the full path....
WHY?!?!?!?!?!?!
where am I mistaking?
here is the code:
// home is the instance name for a movieclip.
currentURL = home;
currentURLstring = new String(currentURL);
currentURLstring.substr(7);
StatusUpdate(currentURLstring);
Setting String To Instance Name
i've got an array with 5 strings.
i want to pass these through a for loop and set them as an instance name. the instance name is one of a textInput component. it recognizes the name. but it won't read the .text attribute.
Code:
for (var i:Number = 0; i < mcArray.length; i++)
{
var tempName:MovieClip = mcArray[i];
trace(tempName);
if (tempName.text == "")
{
checkArray[i + 1] = false;
}
else
{
checkArray[i + 1] = true;
}
}
Convert String To Mc Instance
hello
code :
// this bit goes into a TextField prototype
function validate(obj:Object) {
wrongArray.push(obj + "error")
}
// this is my func
if (wrongArray.length<=0) {
sendMail();
} else {
for (i=0; i<wrongArray.length; i++) {
var themc:MovieClip = wrongArray[i];
//trace(typeof(themc) + " / " + i + " // " + wrongArray[i]);
showError(themc)
}
}
}
function showError(mc:MovieClip):Void {
trace(typeof(mc))
}
the output is always String how do i convert this to MovieClip instance
Get Movieclip By Instance Name String
This is a really simple newb question:
Given an instance name in a string variable like var x = "instancename", how can I get the actual movieclip with that instance name?
Thanks in advance!
How To Convert A String To A Instance Name?
Hello!
Im new to coding and ActionScript. I have a problem where I have a String that contains an instance name of a button (lets say the instance name is _level0.application.form1.A1 ), the problem is that I dont know what to do to get to use the buttons instance name ( what i have to do is to make some changes to _level0.application.form1.A1._x and _level0.application.form1.A1._y )
See the code below.
Thanks for the help
PHP Code:
//myNode.firstChild.nodeValue=<msg>_level0.application.form1.A1,100,100</msg>
var myString:String=myNode.firstChild.nodeValue;
//myString= "_level0.application.form1.A1,100,100"
var myArray:Array = myString.split(",");
//myArray[0] = _level0.application.form1.A1 -> toDrag = _level0.application.form1.A1
var toDrag_btn = myArray[0];
// NOW I NEED TO USE THE BUTTON _level0.application.form1.A1
// IT IS NOT DONE LIKE THIS BUT MAYBY YOU GET THE IDEA BELOW
toDrag_btn._x=100;
toDrag_btn._y=100;
Generate Instance Name From String
This is probably a really simple question. I have a movie with say, 10 dynamic textfields called "description1", "description2"... etc
In the actionscript I want to go through a for loop and set the text of each of these fields... how can I do it? IE,
for(var i = 0; i <= 10; i++){
_root.descriptionX.text = i;
}
where "descriptionX" depends on the value of i.
any help will be appreciated.
Convert String To Instance Name
I'm trying to write a function where I can use a string variable to reference a movieclip already on the stage.
Specifically what I want to be able to do is:
-get the name of the MovieClip clicked
-convert the name to a string
-change the string to the name of the next movieclip.
-get the x and y position of the "next movieclip"
I've succeeded up to the point where I need to get the x and y position. Everything I've tried only returns null or undefined.
Here's the relevant code:
ActionScript Code:
var counter:Number = 1;
mc1.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:MouseEvent) {
var mcname:String = event.target.name;
//returns "mc1"
mcname = mc.substr(0,-1);
//returns "mc"
counter ++;
mcname = mcname += counter;
//returns "mc2"
var mcX = mcname.x;
var mcY = mcname.y;
//that last part doesn't work. I'm trying to get the position of mc2 which is already on the stage.
Using A Variable String As An Instance Name
Hey Everyone,
I'm making a map and when you hover over a state it has a pop up with some information, pretty easy stuff. Well, I'm using this as my code(HoverCaption Tutorial)...
Code:
Missouri.onRollOver = function() {
captionFN(true, this._name + "
Carriers: " + ranString[numState] +
"
Total of " + ranCount[numState] + " Carriers.", this);
this.onRollOut = function() {
captionFN(false);
};
};
What I'd like to do is instead of having to make this for every state just pass in the instance name which is the name of the state. I thought my code would look something like this.
for button...
Code:
on (rollOver){
var numState:Number = 25;
var strState:String = this._name;
}
for other code...
Code:
strState.onRollOver = function() {
captionFN(true, this._name + "
Carriers: " + ranString[numState] +
"
Total of " + ranCount[numState] + " Carriers.", this);
this.onRollOut = function() {
captionFN(false);
};
};
Well, that doesn't work, I didn't know if there is a way to do that, maybe threw a method. Thanks for the help!
String To Movieclip Instance Name
Hi,
I have a function to set focus to a movieclip. Something's wrong, not sure what... I'm blinded by this, and need help!
First I'm creating a movieclip container and populating this with movieclips that will make up a menu. Next step is to give focus to the first "tab" initially, and then to have a selecteditem variable that changes as the focus changes...
//Creates an empty movieclip for containing the menu
menu_container = this.createEmptyMovieClip("main_menu_mc", this.getNextHighestDepth());
menu_container._y = 20;
//Counts through the categorynodes_array and adds buttons
//Adds the category name and description to the textfields in "tab"
for (var i = 0; i<_root.categorynodes_array.length; i++) {
var m = menu_container.attachMovie("tab", "tab"+i+"_mc", i);
m.categoryname_txt.text = _root.categorynames_array[i];
m.categorydescription_txt.text = _root.categorydescriptions_array[i];
m._x = 30;
m._y = (m._height+20)*i;
function setTabFocus(tab) {
var tab:Number = tab;
var tab_mc:String = "main_menu_mc.tab" + tab + "_mc";
trace (tab_mc);
if (selectedItem == null) {
//Selection.setFocus(main_menu_mc.tab0_mc);
Selection.setFocus[tab_mc];
} else {
Selection.setFocus(selectedItem);
}
}
setTabFocus(1);
trace(Selection.getFocus());
Pretty please, help me!
[CS3/AS2.0]MovieClip Instance Name To String How?
Hello there , nice joinin the forum....I have a question for you dear folks!
I would like to pass the name of a movieclip to a string so my attachmovie method can work. what I m doin is :
function createBlocks(slot:MovieClip)
{
...
...
for (var i = 4; i < 10; i++)//lines
{
grid[j] = new Array();
for (var j = 0; j < 9; j++)//columns
{
var bName = "block_" + i + "_" + j;
holderClip.attachMovie(slot, bName, depth);
...
...
}
when I call the above function on a keyframe I call it like :
this.createBlocks(block4);
block4 is the id name of a movieclip in the library.
the problem is that the attachMovie method needs a string as a parameter!
how can I convert that to a string? so afterwards, slot , has inside the name "block4" (with the quotation marks)
[AS3] Class Instance From String?
Hi guys,
Is it possible to create a class instance from a string representation of the package/class?
For example, could I turn the following variable into an instance of MyClass?
ActionScript Code:
var str:String = "some.package::MyClass";
Cheers.
String Variable -> Instance Name?
Hello There.
It is possible to use a String to identify a symbol instance?
Let's say I have several instances of a symbol movie clip. The instances are called mc_Symbol_AA, mc_Symbol_BB, mc_Symbol_CC... etc. Also I've defined a string varible called instance_name. Some script assigns this variable a different value every time, so the value will be "AA" or "BB" or "CC"... etc.
What code will be necesary to use this string to build the full name of the instance ("mc_Symbol_" + instance_name, an play it? On something like this:
Code:
on (relase) {
_root.Here will come some fuction to complete the instance name.play()
}
It may be a simple question, but I cannot find any documentation or example for this. Thank You!
Converting Instance Name To String To Use?
Hi,
I have a dynamically created movie clip thats instance name will be something like
_root.emptyportfolio.portfolio.button1_mc
i need to find a way of getting the instance name and assigning it to a string so i can retrieve the 1 from it.
thankyou verymuch.
Referring To Instance Name As String
Before I go into the longwinded version in words, here's what I'm trying to do:
say one instance of multiple mc's is named "main1";
is there a way to script a btn inside of said mc to say something like
on (release){
_root.loadMovie("<<DynamicallyGeneratedNameHere>>.jpg", "emptyClip_mc");
}
where the string inside the carrots, for this example, would be "main1", and of course for all the others would refer to their own mc's instance name ("main2", "main3", etc.)
So now for the longwinded version (if it's even necessary to understand where I'm coming from): I need to have all of my buttons' contents be editable in one fell swwop (and the scripts as well), so the actual scripts will all be the same since all the buttons will be multiple instances of symbols. I would like to make the script within the symbol dynamically refer to different movies (or jpgs) to load. The only way to make that happen would be to use the individual instance names of the buttons in the reference to individual movies. Am I clear? Thanks for any help you may be able to offer
String To Movieclip Instance Name
Hi All,
Is there a way to convert a string to a movieclip instance?
function buttonClicked(e:MouseEvent) {
var myMc = e.target.parent.name;
trace(myMc.x);
}
i get this error
ReferenceError: Error #1069: Property x not found on String and there is no default value. at MethodInfo-99()
Thanks in advance!
Can You Refer To A Instance Name By A String?
i have a program that names various instances like this:
this._name="Car"+count;
count+=1;
now what i need to do is refer to these instances in a while loop:
i.e
_root.Car+""+newcount+""._x=7;
newcount+=1;
thanks
PHP String To Flash Array To Instance Name
This is really anoying me.
I want to use date's that are stored in a SQL database to set MC's in my flashsite to visible false or true.
If I define an array in flash it's no problem.
datumArray = new Array(sep2,sep3,sep4,nov12);
for (var i = 0; i < datumArray.length; ++i){
datumArray[i]._visible = false;
}
created Array is like this;
Variable _level0.datumArray = [object #1, class 'Array'] [
0:[movieclip:_level0.sep2],
1:[movieclip:_level0.sep3],
2:[movieclip:_level0.sep4],
3:[movieclip:_level0.nov12]
]
Variable _level0.i = 4
but the datumArray comes from SQL using PHP. I tried lost os things but always end up with an array that uses quoted names in stead of instance names. Example;
PHP returns datums="sep2,sep3,sep4,nov12"
AS
datumArray=this.datums.split(",");
created Array is like this;
Variable _level0.datumArray = [object #1, class 'Array'] [
0:"sep2",
1:"sep3",
2:"sep4",
3:"nov12"
]
Variable _level0.i = 4
if I leave the "" on my PHP returned string out, Flash won't create the array.
It's really driving me crazy. Can anyone tell me how to create an array that can be used as instance names....so with values like, [movieclip:_level0.sep2],
Access Instance Name From Dynamic Txt String...?
I'm accessing a string (which is also an instance name) from a text file which is loaded on to a dynamic text box. Now I want to access the corresponding movie clip with the same instance name as of that string. So, if you actually look at it, the code would look something like as follows,
Considering the following:
- "varCheck" is the instance name of the dynamic textbox.
- "mc1" is the string it contains AND the instance name of an existing movie clip.
My mission: To play the 2nd frame of "mc1" movieclip...
Presumed code,
_root.varCheck.text.gotoAndPlay(2); <-- this is wrong but it shows what I'm trying to do
So, help anyone?????
Convert String Into MovieClip Instance Name
I want to do something like -
Code:
var theMC:String = "myMovieClip";
value(theMC).getBytesLoaded();
That is, I have a string of movieClip names, and want to get an object var with the same name.
How do I convert a string into an object ?
Thanks
[CS3] Refering To An Instance With A String From An Array
have a variable that will have a differn't string value depending on a random event. I want to use the string that is passed to that variable to move an instance on the stage. Is there someway to do this? I will attach the code to kind of show what im doing. To explain the code a little more the goal of it is to create an array of 4 cards and shuffle them. Once they are shuffled I want to select the first card in the array and move it.
Attach Code
// important packages
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.*;
dealBtn.addEventListener(MouseEvent.CLICK, deal);
function deal(event:MouseEvent):void
{
var cardNames:Array;
var cardValues:Array;
var card1:String = new String();
cardNames = ["aceHeart", "twoHeart", "threeHeart", "fourHeart"];
cardValues = [1,2,3,4];
var shuffled:Array = new Array();
var randomNum:Number;
var randomNum2:Number;
var store:String;
var SwitchValue:Number;
for (var i:uint = 0; i < 3; i++)
{
randomNum = Math.floor(Math.random()*3);
randomNum2 = Math.floor(Math.random()*3);
store = cardNames[randomNum];
cardNames[randomNum] = cardNames[randomNum2];
cardNames[randomNum2]= store;
}
cardNames[1] = card1;
card1.x = 252;
card1.y = 256;
[AS2] Create Instance Of Class From String
I can't figure this out. I want to create a class instance based on the string variable passed to it:
Code:
var className = "someClass";
var sc = new className(); // fail
var sc = new _root.className(); // Throws no errors, but doesn't create a class instance
I searched the forums but the only true solution was as3, and this is as2. Any ideas?
Force Instance Of A Class With A String
Hi,
I've been trying for a while to create a full framework of website menager that can menage different pages with modules and templates via Flash and I've hit a wall with the dynamic class importing.
First the code:
ActionScript Code:
import packages.site.templates.*;
public function changeTemplate(newTempObj:String, newPageName:String):Void{
if(newTempObj != isLoaded.template){
trace(newTempObj+" = "+typeof(newTempObj));
trace(packages.portfolio.templates[newTempObj]);
addTemplate(newTempObj,"tFormulaire", newPageName);
}else{
trace("template already exists!");
}
}
The value of newTempObj is a string, the name of a Class named "Temp_Home".
The problem is that when I trace packages.portfolio.templates[newTempObj], the compiler doesn't import the class into the SWF. However, when I trace packages.portfolio.templates["Temp_Home"] it does. newTempObj is a string and has the right value... but the compiler still doesnt work and I can't just force-type the value as it is parsed from an XML.
Thanks for any help.
Matching A String Literal With An Instance Name
Is there any way to get the ActionScript to load the variable then act on a matching instance name? For example I am creating a dbase driven gaming site. When a review is from Gamecube I want a gamecube logo to pop up in the graphic. I have the logo named "gamecube" as the instance, and the variable read in also is "gamecube" from the systems table in the database. Now I wanted to link the String to the instance, IE "system"._visible = true; Is there any way to do this, because there are many system logos, and instead of having 10+ if statements, I wanted just one that would just turn on the visibility of the instance that matches the String. If anyone can help I would greatly appreciate it.
Return Class Instance As String
Is there anyway to include a function or overrite something in a class that'll output a custom string when the object is called as a string?
So for example if I created a class named "myClass" and I instantiated it:
Code:
var myObject : myClass = new myClass();
When I:
Code:
TextControl.text = "blah blah, " + myObject;
myObject is getting casted as a string. Normally it would output:
"blah blah, [object myClass]"
Is there a built-in function that recast the object as string? Is there anyway for me to change that string output? I know I can just make a public toString() method in the class or something, but just wondering if there was something better.
Converting A String To A MovieClip Instance
hi there guyz,
I needed your help on flash action script…
I wanted to know whether there is any way to convert a variable/string to a movie-clip object/instance?
I know we can use toString() to do it the other way around… But I need to extract a value from an array [which has values pushed into the array that are movie-clip instances and its x & y positions] and then convert this extracted value into a movie-clip instance to set its properties to change the x & y positions of the movie-clip. There seems to be a type mis-match coz the setProperty() returns an undefined value.
M not able to find anything relevant or even close to doing such a thing on the net… if u know… do let me know… its kinda really really urgent… will really appreciate your help.
Thanks in advance,
Regards,
Kavini
Convert String To An Object Instance Name
Hey there,
I'd like to append multiple strings in order to create an instance names. The code is placed below:
// I have 3 buttons contained in a MC with the instance name "container"
// I've created an array of the button instance names
var myArray:Array = new Array (button1, button2, button3);
// I'm using a "for" loop to automate the process
for (i = 0; i < myArray.length; i++){
// Creates a string of the path from root level to the button
var myArray:String = "container." + myArray;
// Trying to convert the string into an object and also abbreviate the path from "container.button1" to "button1"
var myArray:Object = new Object();
// Change all the buttons alphas to 100
myArray._alpha = 100;
}
thanks in Advance!
Susan
(AS2, OOP) Create An Instance Of A Class, By Name (String)?
In as simple an example as I can think of, I have two classes: Dog and Cat. Both are subclasses of Animal, in this stupid example...
I know how to create instances of both, however I don't know how to dynamically create them by name from a string.
It would be something like...
function addAnimal( type:String ):Animal {
return new [type]();
}
Thanks in advance.
Gettign Mc Instance Passed Through A String.
Hi, this is my first post to this forum
I'm trying to dynamically pass different movieclip names as strings to a function in order to tween them but im stuck with making flash understand that the mc names im passing are actual movieclips in the library.
Code:
public function receivedFromJavaScript(mc:String):void {
var tMC:Class = getDefinitionByName(mc) as Class;
var newMc:MovieClip = new tMC() as MovieClip;
Tweener.addTween(newMc, {alpha:1, time:0.2, transition:"linear"});
}
So when I pass "MyMC" to the function abobve i recieve following error:
"ReferenceError: Error #1065: Variable MyMC is not defined."
Could anyone please point me in the right direction with this one?
/I
How To Convert String To Object (movieclip Instance Name)
this is a function on my _root :
function callMsg(title,msg,btn) {
trace("_root.msgBox() is called");
_root.x += 1;
var newName = "x"+_root.x;
duplicateMovieClip("_root.msgBox",newName,_root.x) ;
//////////////////////////////////////////////
//Need to call function startMsg() in the created movieclip
//////////////////////////////////////////////
var xx = (Stage.width/2 - _root.msgBox._width/2);
var yy = (Stage.height/2 - _root.msgBox._height/2);
setProperty(newName,_x,xx);
setProperty(newName,_y,yy);
}
with that i added a line
_root.newName.startMsg();
but it wouldnt work, i thought the reason must be "newName" is a String hence it wouldnt refer to a _root.String but looking for a _root.object
example if newName is "x1", the duped movie clip would be named x1 too
hence i need to call out :
_root.x1.startMsg();
qns is how do i get it to refer newName as a movie clip ?
thx in advance, btw whats the difference between depth and level ? and can i delete my own post here ?
Loops, Combine String With A Variable, Instance Name (mc)
Ello,
First of all, great forum ..
I'm quite new to actionscript, do have experience in java (js) and quite a lot with php, but actionscript? nope ..
I have to do this little project, and I wanted to use a loop for a hitTest for not running thru walls ..
I'm using a walls as a mc with an instance name and then test inside the object that's not suppose to run thru it to do a hitTest that equals the instance name of the wall mc like this;
Code:
(this.hitTest(_root.verticalLeft1))
Now I'm copying this code for all the other walls, verticalLeft2, verticalLeft3, ..4, also using horizontalTop1, horizontalTop2, ..3, etc etc ...
I was planning to use a loop so i don't have to copy it 20(x4) times, like this
Code:
for(var i:Number = 1; i<20; i++) {
var wallName = eval("verticalLeft" + i);
if (this.hitTest(_root.wallName)) { _x = _x+1; speed = 0; }
}
Now, the way I was thinking is that while looping, the wallName should be verticalLeft1, verticalLeft2, 3 etc .. identical to the mc with her instance name .. but it doesn't work .. obviously cause I don't know how else it should work .. Am I not suppose to use a String here? or at all, is it a String? cause var wallName:String = eval("verticalLeft" + i); doesn't work either .. or is eval(); totally wrong? .. pfff i've lost it
in PHP it would be something like ${"verticalLeft".i} .. but it's not php is it!
Well.. any help would be appreciated .. thanks ..
String + Function Parameter = Existing Instance Name
I am doing some form validation and am trying to create a function that will check the text of a TextInput object then change the color of some adjacent dynamic text to indicate that the field has been left blank. I am passing the instance name of the TextInput to the function then I want to attach the string "Text" to the end of the instance name to create the instance name of the adjacent dynamic text field (e.g. coachFirstName --> coachFirstNameText). I am sure this is doable, but am having a hard time getting the right syntax. Here is the code I am using. Thanks!:
Attach Code
var myFormat:TextFormat = new TextFormat();
myFormat.color = 0xA05324;
function checkNaN(fieldName){
if(fieldName.text == "") {
catVar = fieldName + "Text";
catVar.setTextFormat(myFormat)
//fieldName + "Text".setTextFormat(myFormat)
}
}
checkNaN(coachFirstName)
Possible? Address Dynamic Clips By String Contained In Instance Name
Hi,
Is it possible to address any clip whose instance name contains a string?
I am ultimately trying to create a hitTest to see if any of dynamically created clips are clicked on - these clips are created using attachMovie, and are named like attachMovie(...,"string" + number,...) . Is there any way to evaluate a clip to see if it contains "string" in the instance name?
I know what I'm trying to achieve can be done by looping through an array that is filled by these dynamic clips upon their creation, but the loops really slow things down!
Thanks in advance.
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....
Access Property/function Of Instance From Inside Another Instance
Might be something really obvious, but I'm still trying to get my head round as3...
I need to call up a property and function of another instance of the same class, similar as in as2 (called from within "_root.instance_mc1"):
ActionScript Code:
_root.instance_mc2.someNumber = 0;
_root.instance_mc2.someFunction();
Now in AS3 I can access the object (extending sprite) itself (and inherited properties like x) by using:
ActionScript Code:
this.parent.getChildByName("row2").x
but if i try to access public variables/functions from that object (this.parent.getChildByName("row2").someNumber) I get Error 1119: Access of possibly undefined property someNumber through a reference with static type flash.displayisplayObject.
Anyone know how I can get this to work?
Code In One Instance Is Referencing The Previous Instance
I have the following code in a button symbol:
on (release) {
gotoAndStop (2);
_root["answer" + this._name.substr(1)] = "true";
}
I also have an instance of the button in 2 consecutive keyframes. The first instance is named "Q5" and the second instance is "Q6".
I expected the code: this._name.substr(1)]
to reference "5" and "6" from the instance names (Q5 and Q6), but instead instance "Q6" is referencing "Q5"!
The *really* strange thing, is that when I insert a blank keyframe between the two original keyframes, the code works perfectly!
Does anyone know what's happening?
[MX04] Get Instance Name Of Rolled Over Array Instance
Hi
I am willing to do a rollover image gallery which enlarges image on rollover event and shifts the neighbouring ones aside..
Here is the code so far
Code:
_root.bttn.onRelease = function() {
createGallery();
};
function createGallery() {
var row11:Array = new Array("DSCF5659", "DSCF5807q", "DSCF5773q");
for (i in row11) {
_root.createEmptyMovieClip(row11[i], _root.getNextHighestDepth());
_root[row11[i]].loadMovie("segi/"+row11[i]+"small.jpg", [row11[i]]);
_root[row11[i]]._x = i*150;
}
}
_root.onEnterFrame = function() {
function roll() {
var row11:Array = new Array("DSCF5659", "DSCF5807q", "DSCF5773q");
for (i;i<row11.length;i++) {
_root[row11[i]].onRollOver = function() {
this._xscale += 10;
};
}
}
roll();
};
What I would like to do is to:
ask flash which particular movieclip was rolled over , what is its instance name and than perform string operation to get a number (order) of that clip (I am naming all dynamically with image name + number in order)
Can anyone help me please ???
Thanx in advance
How Do I Copy A Sprite Instance Into A BitmapData Instance?
I apologize if this is covered elsewhere: I just don't even know what terms to search on to find what I'm looking for...
I have a sprite that receives various user-drawn lines on it during runtime. I would like to be able to copy this Sprite into a BitmapData instance, then send the pixels from the BitmapData instance to a PHP script. I think I'll be all right with the PHP end of things, but I just don't know how to copy my Sprite into a BitmapData.
(If there were a way to just use BitmapData and use the moveTo, lineTo, mouseX, mouseY, etc, methods, then I'd do that, but I don't even know if that's possible...Obviously, I'm not as well-versed in AS3 as I'd like to be.)
Thanks in advance for any help!
Error 2101: The String Passed To UrlVariables.decode() Must Be Url-encoded Query String
I am trying to make a flash contact form which will submit the firstname, lastname, email and comments to an asp.net page.
I am have having the following error:
Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs
I am using the following action script code as pasted below. This action script is communicating with an asp.net file to send the email out. In the end it responds back with response=passed or failed.
I have already spent around 3 hours figuring it out.. and looking through the internet for resolution but no luck. Any help will be appreciated.
stop();
submit_btn.addEventListener(MouseEvent.CLICK, submit);
function submit(e:MouseEvent):void
{
var variables:URLVariables = new URLVariables();
variables.firstname = firstname_txt.text;
variables.lastname = lastname_txt.text;
variables.email = email_txt.text;
variables.comments2 = comments_txt.text;
var req:URLRequest = new URLRequest(”emailacount.aspx”);
req.method = URLRequestMethod.POST;
req.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, sent);
loader.addEventListener(IOErrorEvent.IO_ERROR, error);
loader.load(req);
status_txt.text = “Sending…”;
}
function sent(e:Event):void
{
status_txt.text = “Your email has been sent.”;
firstname_txt.text = “”;
lastname_txt.text = “”;
email_txt.text = “”;
comments_txt.text = “”;
}
function error(e:IOErrorEvent):void
{
status_txt.text = “There was an error. Please try again later.”;
}
and the following asp.net code:
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Net.Mail" %>
<script language="VB" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Try
Dim fromEmailAddress = "paul@lancierinc.com"
Dim toEmailAddress = "rizwandar@gmail.com"
Dim firstName = Request.QueryString("firstname_txt")
Dim lastName = Request.QueryString("lastname_txt")
Dim comments = Request.QueryString("comments_txt")
Dim userEmail = Request.QueryString("email_txt")
'create the mail message
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress(fromEmailAddress)
mail.To.Add(toEmailAddress)
'set the content
mail.Subject = "Email from" & firstName & " " & lastName
mail.IsBodyHtml = True
Dim strBody As String = "<b>Email from</b>" & " " & firstName & " " & lastName & "<br><b>Email Address:</b> " & userEmail & "<br><b>Comments:</b> " & comments
mail.Body = strBody
'send the message
Dim smtp As New SmtpClient("mail.lancierinc.com")
smtp.Send(mail)
Dim urltoencodestring2 = "response=passed&err=0"
'Response.Write(urltoencodestring2)
Catch smtpEx As SmtpException
'A problem occurred when sending the email message
'ClientScript.RegisterStartupScript(Me.GetType(), "OhCrap", String.Format("alert('There was a problem in sending the email: {0}');", smtpEx.Message.Replace("'", "'")), True)
Response.Write(smtpEx.Message)
Dim urltoencodestring = "response=failed&err=1"
'Response.Write(urltoencodestring)
Catch generalEx As Exception
'Some other problem occurred
'ClientScript.RegisterStartupScript(Me.GetType(), "OhCrap", String.Format("alert('There was a general problem: {0}');", generalEx.Message.Replace("'", "'")), True)
Dim urltoencodestring3 = "response=failed&err=1"
'Response.Write(urltoencodestring3)
End Try
End Sub
</script>
String Passed To URLVariables.decode() Must Be A URL-encoded Query String...
I really don't understand why this won't work? I've made a test which sends some POST data to a script on my page which works fine. But why does not this work?
Code:
var mapsize = _cmap.fieldx.toString(16) + _cmap.fieldy.toString(16);
var names = "Zomis_AI6";
var description = "descr";
var result = "gameresult";
var upldata: String = "mapsize="+mapsize+"&names="+names+"&description="+description+"&result="+result;
trace(upldata);
var variables:URLVariables = new URLVariables(upldata);
var request2:URLRequest = new URLRequest();
request2.url = "http://www.zomis.net/record.php";
request2.method = URLRequestMethod.POST;
request2.data = variables;
var loader2:URLLoader = new URLLoader();
loader2.dataFormat = URLLoaderDataFormat.VARIABLES;
loader2.addEventListener(Event.COMPLETE, uploadcomplete);
try {
loader2.load(request2);
trace("Loaded");
}
catch (error:Error) {
trace("Unable to load URL");
}
Tracing gets:
Code:
mapsize=1010&names=Zomis_AI6&description=descr&result=gameresult
Loaded
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables$iinit()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
Randomize String And Create Textfields With String Txts
Hi,
is there some easy method to randomize elements of an array (to randomize index numbers) and create textfields with name of these elements ?
I had no problem making a photo gallery with strings but now I have to do a menu , with spacing (there should be same space between all the words of an array generated textfields)...How can this be accomplished ?Thanx in advance, Meerah
Convert Multiline String To A One Line String With RegExp
better get my own thread for that
How can I convert a multiline String to a one line String?
EX:
PHP Code:
Testing is always full of man made bugs.
<a href="http://www.betterthannothing.com" title="betterthannothing" target="_blank">
<font color="#22229C">Believe</font>
</a>
me when times comes that you have to
<a href="http://www.vreate.com" target="_blank">create</a>
useless stuff to test some other useless stuff to have
<a href="http://www.vreate.com">some</a>
real results.. its a pain.
<img src="http://www.markval.com/deerPack.jpg" height="484" width="352"/>
<em>Got to try that stuff to eventually love it one day.</em>
and should result in
Code:
Testing is always full of man made bugs.<a href="http://www.betterthannothing.com" title="betterthannothing" target="_blank"> <font color="#22229C">Believe</font></a>me when times comes that you have to<a href="http://www.vreate.com" target="_blank">create</a>useless stuff to test some other useless stuff to have<a href="http://www.vreate.com">some</a>real results.. its a pain.<img src="http://www.markval.com/deerPack.jpg" height="484" width="352"/><em>Got to try that stuff to eventually love it one day.</em>
I think it have to play with the ^ (caret) and m (multiline) ... just need to put the puzzle together.
String.as (Fishing Line Or Kite String)
Hello everyone. After reading the article on Glen Rhodes (Proud Canadian) I was wondering exactly how to insert the string.as file. I have been having huuuuuuge speed issues with my code. My file sizes are quite small (40 - 60 k)but they are very sluggish.
Thank you......
Please help
http://www.moodvibe.com
Trouble With String.indexOf And String.lastIndexOf
Hi,
I have an input text field used for time. I'm trying to set it up so the user has to enter a valid time into the box.
I set the box to be only 5 characters in length and to only use numbers and the ":" character.
I thought this code would insure there wouldn't be two ":" characters and the ":" would be at lease one character from the begining and at least two from the end.
But the if you enter 2:321 it comes back as a valid time.
Thanks in advance,
thurston
Code:
if(string.indexOf(":", 1) == string.lastIndexOf(":", string.length-3) ){
trace("Valid Time");
}else{
trace("Invalid Time!!!");
}
Changing A String Name In A Loop / Concatonating String Name?
Hey all,
Does anybody know of a way to change a string name as a loop proceeds?
This is the main piece of code that I wish to loop with i incrementing, so that whilst i=0 then:
_root.barARed._visible=barRed[i];
_root.barARed._width=barLength[i];
_root.barAYellow._visible=barYellow[i];
_root.barAYellow._width=barLength[i];
_root.barAGreen._visible=barGreen[i];
_root.barAGreen._width=barLength[i];
infoA.text=info[i];
and i=2 then:
_root.barBRed._visible=barRed[i];
_root.barBRed._width=barLength[i];
_root.barBYellow._visible=barYellow[i];
_root.barBYellow._width=barLength[i];
_root.barBGreen._visible=barGreen[i];
_root.barBGreen._width=barLength[i];
infoB.text=info[i];
and so on...I would use _root.barRedInstanceName[i]._visible=barRed[i]; but I can't give the movie clip (the bar) an instance name such as redBar[1], redBar[2] etc. (system reserved I'm told)
I guess what I am trying to ask in a roundabout way: is how do you concatonate the name, rather than the contents of a string?
Hope you'll forgive me if this is something really simple that I am overlooking, but I only have a very short experience of flash.
Thanks
Al
Ball Bouncing On String: Getting The String To Be Bigger?
I have a black line which is simply a movie clip and a yellow circle which is also a movie script. The ball works great, it bounces on the bottom of the movie, and you can pick it up and throw it around. So now I want to attach the ball to the black line. So:
1. How can I make it so that the top part of the line will stay in one position, and so that a bottom part of it will move around? Is there any way I can link the two at a certain point so that wherever the ball goes the line will stay attached to it at that point?
2. In an attempt to try and reach this point I came up with this script in the ball for when it is not being dragged anywhere. The most important bit is really the bottom:
ActionScript Code:
} else {
old.x = pos.x;
old.y = pos.y;
pos.x = _x;
pos.y = _y;
vel.x = (pos.x-old.x)*2;
vel.y = (pos.y-old.y)*2;
//Finds the change in position and adds that as an extention to the line:
_root.ballstring.height += (old.y - pos.y);
Anyone reckon they could help me out? Thanks!
|