actionscript 3.0 - actionscript

I have a picture sliding on my scene, with fade in and out pictures between frames 1 and 100. I would like to create 2 buttons that could go to previous picture and next picture and I just can figure out the code. Need help pls. I tryed like this on last frame, 2 ways:
gotoAndPlay(1);
btnA.addEventListener(MouseEvent.CLICK, backward);
btnB.addEventListener(MouseEvent.CLICK, forward);
function backward(event:MouseEvent)
{
if(this.currentFrame == (1, 30))
{
gotoAndPlay(66);
}
else
{
gotoAndPlay(1);
}
}
function forward(event:MouseEvent)
{
if(this.currentFrame == 1, 30)
{
gotoAndPlay(31);
}
if(this.currentFrame == 31, 65)
{
gotoAndPlay(66);
}
if(this.currentFrame == 66, 100)
{
gotoAndPlay(1);
}
}

for all statements you should do:
...
if(event.target.currentFrame == 1 || event.target.currentFrame == 30)
{
gotoAndPlay(31);
}
....

Related

Expected expression before else statement

I get an error saying Expected expression before my else-statement but I do not know why. I searched through other posts but I cant find a solution.
- (void)setDeviationSize:(double)newDeviation
{
if (newDeviation != 0) {
deviationLayer.lineWidth = 2.0 / newDeviation;
if (newDeviation * pixelPerMeter * scrollView.zoomScale < 2 * cPointRadius) {
deviationLayer.hidden = YES;
} else {
deviationLayer.hidden = NO;
deviationLayer.transform = CATransform3DMakeScale(newDeviation, newDeviation, 0);
}
} else {
deviationLayer.hidden = YES;
} else <---- EXPECTED EXPRESSION {
for(LectureModel* lecture in lectures) {
NSString *title;
if([lecture.title length] > 30) {
title = [NSString stringWithFormat:#"%#...", [lecture.title substringToIndex:30]];
} else {
title = lecture.title;
}
[alert addActionWithTitle:title handler:^(UIAlertAction * _Nonnull action) {
LectureModel* full = [LectureModel findById:lecture.id];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self showModelInPopover:full];
} else {
[[TransitionManager shared] openModelInCatalog:full];
}
}
[self presentViewController:alert animated:YES completion:nil];
}
}
}
What am I missing?
Like vadian and luk2302 pointed out you have an if statement with two else attached to it, so the compiler doesn't understand what the second else is related to and throwing the error.
Maybe you wanted something like
if (newDeviation != 0) {
/* do something */
} else if (someCondition) {
/* do something different */
} else {
/* do something else */
}
If this is not the logic you want, please explain what you want to achieve, so we can help you better.
#user12372692
In order to achieve what you want, there are two ways to solve this -
A. if else condition making.
B. using switch case.
Way A :-
if else condition is written like following :-
if (condition 1) {
/* do something for condition 1 is true */
} else if (condition 2) {
/* do something for condition 2 is true */
} else {
/* do something for both condition 1 and 2 are false. */
}
so as per this your condition should be :-
if (newDeviation != 0) {
/* do something */
} else if (OtherCondition) {
/* do something*/
} else {
/* do something for both above two conditions are false */
}
Way B :-
switch(newDeviation){
case (newDeviation != 0 ) : {/* Do your work */}; break;
case (condition 2) : {/* Do your work */}; break;
case (condition 3) : {/* Do your work */}; break;
}

How to trigger mouse click prgrammatically in vaadin ? button.click() isn't doing the job

I am trying to create a custom pagination and below is small part of the logic. When clicking the ">" button it should change the page i.e click the next page's button programmatically. I tried button.click() but it isn't working for me either. I am new to vaadin so please help.
for(int i=0;i<v.size();i++) {
Button b = v.get(i);
b.addClickListener(e->{
if(b.getCaption()==">") {
if(page%5==0) {
final int mn = Math.min(v.size()-2,page+5);
grid.removeAllComponents();
grid.addComponent(pre, 2, 3);
int j = 1;
for(j=1;j<mn-page+1;j++) {
grid.addComponent(v.get(page + j-1),3+j,3);
}
grid.addComponent(ne, j+4, 3);
}
bt = v.get(page);
bt.click();
page++;
}
else if(b.getCaption()=="<") {
if(page%5==1) {
grid.removeAllComponents();
grid.addComponent(pre, 2, 3);
int j = 1;
for(j=5;j>0;j--) {
grid.addComponent(v.get(page - j-1),9-j,3);
}
grid.addComponent(ne, 10, 3);
}
page--;
}
else{
page=Integer.parseInt(b.getCaption());
}
if(page==v.size()-2) ne.setEnabled(false);
else ne.setEnabled(true);
if(page==1) pre.setEnabled(false);
else pre.setEnabled(true);
});
}

how to set max resolution for each features in openlayers3

Hello i am trying to do different styles for different features and i got and working fine,now i want to set different resolution for different features.I tried doing this way but not working.Can u please Help this?
style: function (feature, resolution) {
//var test = (resolution >= 200) ? (feature.get('class') === 'xx') : '';
//resolution: test;
if (feature.get('class') === '---') {
max Resolution: 100;
return style1;
}
else if (feature.get('class') === 'xx')
{
return Style2;
}
else if (feature.get('class') === '---')
{
return style3;
}
else if(feature.get('class')==='ii')
{
return style4;
}
else if(feature.get('class')==='mm')
{
return style5;
}
},
You should be able to resolve this with simple boolean logic. Something like this:
style: function(feature, resolution) {
var class = feature.get('class');
if (resolution >= 200) {
if (class == 'xx') {
return style200xx;
} else if (class == 'xy') {
return style200xy;
}
} else if (resolution < 200) {
if (class == 'xx') {
return style0xx;
} else if (class == 'xy') {
return style0xy;
}
}
}
If you have many different cases, it might make sense to define a separate ol.layer.Vector for each resolution range, and use the same source for all layers. Inside the style functions, you will then only have to handle the feature class.

How to call a random function in Unity3d

in iOS I would simply use this;
if (arc4random() % 2 == 0) {
//Do 1 Thing
}else{
// Do another
}
What would be the same method but using Unity3D for that ?
From unity's documentation:
if (Random.Range(minVal, maxVal) % 2 == 0) {
//Do 1 Thing
} else {
// Do another
}
random values has been put.
if(Random.Range(-10000, 10000)%2==0)

gmaps4rails show hide functionality

I'm hoping to get a little bit of insight on show / hide functionality in gmaps4rails.
example functionality
// == shows all markers of a particular category, and ensures the checkbox is checked ==
function show(category) {
for (var i=0; i<gmarkers.length; i++) {
if (gmarkers[i].mycategory == category) {
gmarkers[i].setVisible(true);
}
}
// == check the checkbox ==
document.getElementById(category+"box").checked = true;
}
// == hides all markers of a particular category, and ensures the checkbox is cleared ==
function hide(category) {
for (var i=0; i<gmarkers.length; i++) {
if (gmarkers[i].mycategory == category) {
gmarkers[i].setVisible(false);
}
}
// == clear the checkbox ==
document.getElementById(category+"box").checked = false;
// == close the info window, in case its open on a marker that we just hid
infowindow.close();
}
// == a checkbox has been clicked ==
function boxclick(box,category) {
if (box.checked) {
show(category);
} else {
hide(category);
}
// == rebuild the side bar
makeSidebar();
}
function myclick(i) {
google.maps.event.trigger(gmarkers[i],"click");
}
// == rebuilds the sidebar to match the markers currently displayed ==
function makeSidebar() {
var html = "";
for (var i=0; i<gmarkers.length; i++) {
if (gmarkers[i].getVisible()) {
html += '<a href="javascript:myclick(' + i + ')">' + gmarkers[i].myname + '<\/a><br>';
}
}
document.getElementById("side_bar").innerHTML = html;
}
So, in my controller, I'm building a list of markers, and including their categories as json.
#markersLoc = #locSearch.to_gmaps4rails do |loc, marker|
letter.next!
marker_image = "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=#{letter}|82ABDD|000000"
marker.infowindow render_to_string(partial: '/events/info',
locals: {object: loc})
marker.picture({picture: marker_image,
width: 32,
height: 32,
marker_anchor: [11,30],
shadow_picture: "http://chart.apis.google.com/chart?chst=d_map_pin_shadow",
shadow_width: 110,
shadow_height: 110,
shadow_anchor: [12,34]})
marker.title loc.what
marker.sidebar render_to_string(partial: '/events/sidebar',
locals: {object: loc, letter: marker_image})
marker.json({cat: loc.category})
end
I'm kind of stuck, here. I know the :cat string is available (ex: 1,3,4), but I'm not sure how to use it to achieve what I'm after.
Was able to pretty much use what was there, with some modification. This gave me functionality to have 9 categories (could be more or less), and only view what I want. Awesome.
// == shows all markers of a particular category, and ensures the checkbox is checked ==
function show(category) {
var regEx = new RegExp("[" + category + "]")
for (var i=0; i<Gmaps.map.markers.length; i++) {
if (Gmaps.map.markers[i].cat) {
if (Gmaps.map.markers[i].cat.match(regEx)) {
Gmaps.map.showMarker(Gmaps.map.markers[i]);
}
}
}
// == check the checkbox ==
document.getElementById(category+"box").checked = true;
}
// == hides all markers of a particular category, and ensures the checkbox is cleared ==
function hide(category) {
var regEx = new RegExp("[" + category + "]")
for (var i=0; i<Gmaps.map.markers.length; i++) {
if (Gmaps.map.markers[i].cat) {
if (Gmaps.map.markers[i].cat.match(regEx)) {
Gmaps.map.hideMarker(Gmaps.map.markers[i]);
}
}
}
// == clear the checkbox ==
document.getElementById(category+"box").checked = false;
// == close the info window, in case its open on a marker that we just hid
// Gmaps.map.infowindow.close();
}
// == a checkbox has been clicked ==
function boxclick(box,category) {
if (box.checked) {
show(category);
} else {
hide(category);
}
}

Resources