|
-
passing values
Hello,
I tried to passing values. Example.
I have Button_45 and Button_23. Now it flash loaded then it passing default value.
Actionscript Code:
var nice:String="value 1"; // if i pressed Button_45 then var nice:String="value 45"; // if i pressed Button_23 then var nice:String="value 23";
// if i pressed some button it gives value else gives default value like on the top trace("Value whati choose is: " + nice);
Please somebody help how can i do this?
Best,
-
That cannot be your actual code. It would give errors about redeclaring the nice variable.
Post your actual code.
You are probably redeclaring your variable inside your event handler, which means you are not changing the larger scoped variable with the same name.
-
 Originally Posted by 5TonsOfFlax
That cannot be your actual code. It would give errors about redeclaring the nice variable.
Post your actual code.
You are probably redeclaring your variable inside your event handler, which means you are not changing the larger scoped variable with the same name.
Thank u for the answer. I dont have a code i start with new flash project. How can i to this
Actionscript Code:
if (obj.myDProp=="a") { trace ("Valu A"); } else { trace ("Error"); }
Now i want to change obj.MyDProp value with clicking button? and if i dont press the button then trace print Error
-
If you have a variable and you want to change its value, then just re-assign it. Do not redeclare it.
Code:
var a:String = "hi";
function someButtonHandler(evt:MouseEvent):void{
a = "hello"; //Do not use "var" here if you want to set the a variable above.
}
-
 Originally Posted by 5TonsOfFlax
If you have a variable and you want to change its value, then just re-assign it. Do not redeclare it.
Code:
var a:String = "hi";
function someButtonHandler(evt:MouseEvent):void{
a = "hello"; //Do not use "var" here if you want to set the a variable above.
}
Actionscript Code:
b1_btn.addEventListener(MouseEvent.CLICK, btnPressed); var obj:String = "hi";
function btnPressed(evt:MouseEvent):void { obj = "a"; }
if (obj=="a") { trace ("Value A"); } else { trace ("Error"); }
No i tried this but if i pressed button it dont change nothing happend. Output shows only trace Error. If i click button output dont change trace Value A? Whats wrong?
-
Of course it shows "Error". The code that does the if and trace runs before you have a chance to click the button.
When do you want that code to run?
-
 Originally Posted by 5TonsOfFlax
Of course it shows "Error". The code that does the if and trace runs before you have a chance to click the button.
When do you want that code to run?
I need to start this every button click but i need to set a default value to. Like if i pressed button it change var obj.String value and delete previouse value?
-
Was that a question? I don't know what you're trying to say.
If you want to test the value of obj on every button click, do that in an event handler.
Code:
var obj:String = "hi";
b1_btn.addEventListener(MouseEvent.CLICK, btnPressed);
addEventListener(MouseEvent.CLICK, testObjValue);
function btnPressed(evt:MouseEvent):void{
obj = "a";
}
function testObjValue(e:MouseEvent):void{
if (obj=="a") {
trace ("Value A");
} else {
trace ("Error");
}
}
-
 Originally Posted by 5TonsOfFlax
Was that a question? I don't know what you're trying to say.
If you want to test the value of obj on every button click, do that in an event handler.
Code:
var obj:String = "hi";
b1_btn.addEventListener(MouseEvent.CLICK, btnPressed);
addEventListener(MouseEvent.CLICK, testObjValue);
function btnPressed(evt:MouseEvent):void{
obj = "a";
}
function testObjValue(e:MouseEvent):void{
if (obj=="a") {
trace ("Value A");
} else {
trace ("Error");
}
}
Sorry my english is bad yes. I tried to explain. shortly i need to delete previouse value and replace to new one with button click
Actionscript Code:
// Flash start var obj:String = "hi"; trace ("Error:" + obj); // If button clicked delete previouse var obj:String="hi"; and start new one var obj:String="Value A"; var obj:String = "value A"; trace("Value: " + obj);
if this possible? Thank for your time!
-
You do not need to "delete" the old variable. Simply re-assigning it as we have done above will give it the new value.
-
Can i but it some another var? is there some ways? Thanks again for your time
Actionscript Code:
var obj:String = "hi"; b1_btn.addEventListener(MouseEvent.CLICK, btnPressed); addEventListener(MouseEvent.CLICK, testObjValue);
function btnPressed(evt:MouseEvent):void{ obj = "a"; }
function testObjValue(e:MouseEvent):void{ if (obj=="a") { trace ("Value A"); } else { trace ("Error"); } } var another:String="var"+obj;
-
I'm sorry, but I still don't know what you're trying to say. Perhaps you could write it in your native language and use google translate.
If you are asking whether you can assign the value of one variable to another, then yes, of course you can.
Code:
var another:String = obj;
But be aware of when you do that assignment. In the code you just posted, the variable another will have the value "varhi". I don't think that's what you want.
-
 Originally Posted by 5TonsOfFlax
I'm sorry, but I still don't know what you're trying to say. Perhaps you could write it in your native language and use google translate.
If you are asking whether you can assign the value of one variable to another, then yes, of course you can.
Code:
var another:String = obj;
But be aware of when you do that assignment. In the code you just posted, the variable another will have the value "varhi". I don't think that's what you want.
Yes i know no if i press button b1_btn the it have to be var another:String = "a"; ?
-
Do you mean this?
Code:
function btnPressed(evt:MouseEvent):void{
obj = another;
}
-
 Originally Posted by niceguy7654
Can i but it some another var? is there some ways? Thanks again for your time
Actionscript Code:
var obj:String = "hi"; b1_btn.addEventListener(MouseEvent.CLICK, btnPressed); addEventListener(MouseEvent.CLICK, testObjValue);
function btnPressed(evt:MouseEvent):void{ obj = "a"; }
function testObjValue(e:MouseEvent):void{ if (obj=="a") { trace ("Value A"); } else { trace ("Error"); } } var another:String="var"+obj;
"obj" must change every button click and if button not clicked "obj" have to be "hi"
-
1) what must obj change to?
2) when do you need to check for button click? You obviously cannot check in a listener for click on the button, because then it would always have been clicked.
-
 Originally Posted by 5TonsOfFlax
1) what must obj change to?
2) when do you need to check for button click? You obviously cannot check in a listener for click on the button, because then it would always have been clicked.
I trie to give
Actionscript Code:
private var xmlURL:String = "xml/main"+output_txt.text+".xml";
wich open another xml default loads main1.xml and after i click button it open main2.xml? I think i cant make it with this? Sorry i want to learn but this do not work
-
Okay. Let's see if I finally get what you're trying to do.
Code:
private var xmlURL:String = "xml/main"+output_txt.text+".xml";
b1_btn.addEventListener(MouseEvent.CLICK, btnPressed);
function btnPressed(evt:MouseEvent):void{
xmlURL = "xml/main2.xml";
loadXml(xmlURL);
}
function loadXml(someURL:String):void{
//do your loading code here.
}
loadXml(xmlURL); //this is the initial default load.
-
THANK UUUUUU u are best. This is exactly what i want! thaank uuuuuuuuu again
-
Hello,
I have one problem. The buttons are wrong place now. If i resize browser then button stays width and height. But i need to make then fluid. like page? Or can i but them into another Frame and click them there? Now i have to but them root timeline only then buttons work. If i but them another frame then button click does not to anything?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|