-
Flash CS5 - How to Change AS3 to AS2
Dear Helpers
I am trying to help a student create a combo box, that has several drop down options, and each one should lead to a different image appearing. I can get it to work in AS3 with the following Actionscript, but the students work has been done in AS2, so would really appreciate some help in amending it please.
Thanks in advance
Jenn
import flash.events.Event;
import flash.events.Event;
stop();
combobox.addItem( { label: "A" })
combobox.addItem( { label: "B" })
combobox.addItem( { label: "C" })
combobox.addItem( { label: "D" })
combobox.addItem( { label: "E" })
combobox.addItem( { label: "F" })
combobox.addItem( { label: "G" })
combobox.addEventListener(Event.CHANGE, changeimage);
function changeimage (event:Event) :void{
if (combobox.selectedItem.label == "A") gotoAndStop(40);
if (combobox.selectedItem.label == "B") gotoAndStop(41);
if (combobox.selectedItem.label == "C") gotoAndStop(42);
if (combobox.selectedItem.label == "D") gotoAndStop(43);
if (combobox.selectedItem.label == "E") gotoAndStop(44);
if (combobox.selectedItem.label == "F") gotoAndStop(45);
if (combobox.selectedItem.label == "G") gotoAndStop(46);
}
-
.
Hi,
Try
PHP Code:
stop();
combobox.addItem({label:"A"});
combobox.addItem({label:"B"});
combobox.addItem({label:"C"});
combobox.addItem({label:"D"});
combobox.addItem({label:"E"});
combobox.addItem({label:"F"});
combobox.addItem({label:"G"});
var comboListener:Object = new Object();
combobox.addEventListener("change",comboListener);
comboListener.change = function()
{
trace(combobox.selectedItem.label);
if (combobox.selectedItem.label == "A")
{
gotoAndStop(40);
}
if (combobox.selectedItem.label == "B")
{
gotoAndStop(41);
}
if (combobox.selectedItem.label == "C")
{
gotoAndStop(42);
}
if (combobox.selectedItem.label == "D")
{
gotoAndStop(43);
}
if (combobox.selectedItem.label == "E")
{
gotoAndStop(44);
}
if (combobox.selectedItem.label == "F")
{
gotoAndStop(45);
}
if (combobox.selectedItem.label == "G")
{
gotoAndStop(46);
}
};
or you could do it slightly differently, this way you can add the listener to mulitple combo boxes
PHP Code:
stop();
combobox.addItem({label:"A"});
combobox.addItem({label:"B"});
combobox.addItem({label:"C"});
combobox.addItem({label:"D"});
combobox.addItem({label:"E"});
combobox.addItem({label:"F"});
combobox.addItem({label:"G"});
var comboListener:Object = new Object();
combobox.addEventListener("change",comboListener);
comboListener.change = function(e:Object)
{
trace(e.target.selectedItem.label);
if (e.target.selectedItem.label == "A")
{
gotoAndStop(40);
}
if (e.target.selectedItem.label == "B")
{
gotoAndStop(41);
}
if (e.target.selectedItem.label == "C")
{
gotoAndStop(42);
}
if (e.target.selectedItem.label == "D")
{
gotoAndStop(43);
}
if (e.target.selectedItem.label == "E")
{
gotoAndStop(44);
}
if (e.target.selectedItem.label == "F")
{
gotoAndStop(45);
}
if (e.target.selectedItem.label == "G")
{
gotoAndStop(46);
}
};
Last edited by fruitbeard; 11-25-2014 at 10:33 AM.
-
Originally Posted by fruitbeard
Hi,
Try
PHP Code:
stop();
combobox.addItem({label:"A"});
combobox.addItem({label:"B"});
combobox.addItem({label:"C"});
combobox.addItem({label:"D"});
combobox.addItem({label:"E"});
combobox.addItem({label:"F"});
combobox.addItem({label:"G"});
var comboListener:Object = new Object();
combobox.addEventListener("change",comboListener);
comboListener.change = function()
{
trace(combobox.selectedItem.label);
if (combobox.selectedItem.label == "A")
{
gotoAndStop(40);
}
if (combobox.selectedItem.label == "B")
{
gotoAndStop(41);
}
if (combobox.selectedItem.label == "C")
{
gotoAndStop(42);
}
if (combobox.selectedItem.label == "D")
{
gotoAndStop(43);
}
if (combobox.selectedItem.label == "E")
{
gotoAndStop(44);
}
if (combobox.selectedItem.label == "F")
{
gotoAndStop(45);
}
if (combobox.selectedItem.label == "G")
{
gotoAndStop(46);
}
};
or you could do it slightly differently, this way you can add the listener to mulitple combo boxes
PHP Code:
stop();
combobox.addItem({label:"A"});
combobox.addItem({label:"B"});
combobox.addItem({label:"C"});
combobox.addItem({label:"D"});
combobox.addItem({label:"E"});
combobox.addItem({label:"F"});
combobox.addItem({label:"G"});
var comboListener:Object = new Object();
combobox.addEventListener("change",comboListener);
comboListener.change = function(e:Object)
{
trace(e.target.selectedItem.label);
if (e.target.selectedItem.label == "A")
{
gotoAndStop(40);
}
if (e.target.selectedItem.label == "B")
{
gotoAndStop(41);
}
if (e.target.selectedItem.label == "C")
{
gotoAndStop(42);
}
if (e.target.selectedItem.label == "D")
{
gotoAndStop(43);
}
if (e.target.selectedItem.label == "E")
{
gotoAndStop(44);
}
if (e.target.selectedItem.label == "F")
{
gotoAndStop(45);
}
if (e.target.selectedItem.label == "G")
{
gotoAndStop(46);
}
};
-
Dear Fruitbread
Thank you so much for getting back so quick. I gave both options a go and both allowed me to choose an image from the drop down list - but only once. When I click on the combobox again the list is empty. I'd really appreciate any further suggestions.
Thanks.
Jenn
-
.
Hi,
I assume the comboBox is placed across all frames?
Attach your *.fla, as it's easier to try and help with your file.
If you are unable to attach it maybe link to it. AS2 or AS3 is fine.
-
.
Hi,
here you go, play around with this,
-
Originally Posted by fruitbeard
Hi,
here you go, play around with this,
Dear Fruitbread
Have had a play and I think I may have become confused! Had another go and took out the "data" and "label" I had put in the combobox Properties and your code worked. Thanks for the example zipped file too. Really appreciate the help. I am sure I will be back on the forum with more "tearing my hair out" moments and it is such a relief that there are people out there willing to give up their time. Thanks again.
Jenn
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
|