I have a simple button and i want to make some transitions.
If current frame is 1 I want to play frame 2.
If current frame is 2 I want to play frame 3.
If current frame is 3 I want to play frame 1.
Why my script doesn't work in ActionScript 3.0? Thanks.
buton1.addEventListener(MouseEvent.CLICK, buton1Click);
function buton1Click(event:MouseEvent):void{
if(currentFrame == 1){
gotoAndStop(2);
}
if(currentFrame == 2){
gotoAndStop(3);
}
if(currentFrame == 3){
gotoAndStop(1);
}
}
Your if blocks are always true - you move to the next frame and than test if you're on that frame.
Given your button spans timeline, like so:
Your code would be:
stop();
button1.addEventListener(MouseEvent.CLICK, button1Click);
function button1Click(event:MouseEvent):void
{
switch (currentFrame)
{
case 1:
gotoAndStop(2);
break;
case 2:
gotoAndStop(3);
break;
case 3:
gotoAndStop(1);
break;
}
}
stop();
stage.addEventListener(MouseEvent.CLICK, button1Click);
function button1Click(event:MouseEvent):void {
this.gotoAndStop((this.currentFrame % this.totalFrames) + 1);
}
//this way you can change the timeline without changing code
Related
I am trying to learn to do basic buttons within a spreadsheet to help with a project at school. I am a simple teacher that is trying to find resources to help. I have learned how to create a button that adds one or subtracts one with the value which will allow me to do what I need to do, but ideally I am looking for script code to make a button that would toggle between the values of 1 and 0 upon pressing the button.
Thanks for any help.
function plus1() {
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(
SpreadsheetApp.getActiveSheet().getRange('A1').getValue() + 1
);
}
I believe your goal as follows.
You want to switch the number of 1 and 0 at the cell "A1" on the active sheet by clicking a button.
In this case, at first, it is required to retrieve the value from the cell "A1" on the active sheet. And, the value is put by checking the retrieved value. So how about the following sample script?
Sample script:
function sample() {
var range = SpreadsheetApp.getActiveSheet().getRange('A1');
var value = range.getValue();
if (value == 1) {
range.setValue(0);
} else if (value == 0) {
range.setValue(1);
}
}
In this case, when the cell "A1" is not 1 or 0, the value in the cell is not modified.
References:
getValue()
setValue(value)
if...else
function toggleActiveCell() {
const sh=SpreadsheetApp.getActiveSheet();
const rg=sh.getActiveCell();
rg.setValue(rg.getValue()?0:1);
}
function toggleUniqueCell() {
const sh=SpreadsheetApp.getActiveSheet();
const rg=sh.getRange(row,col);
rg.setValue(rg.getValue()?0:1);
}
According to my understanding, project.getItems({selected: true}) returns wrong results: I'm selecting a curve, it returns the parent Path: Sketch
Try clicking on a curve or a segment. Whole path will be moved. Then try changing the behavior by setting var workaround = false to var workaround = true to observe desired behavior.
How can I get exactly what is really selected?
Current workaround
I'm currently adding those objects into an array on selection and use those items instead of project.getItems({selected: true}).
The thing is that in Paper.js architecture, curves and segments are not items (they are part of a specific item which is the path). So you shouldn't expect project.getItems() to return anything else than items.
Another thing you have to know is that a path is assumed selected if any of its part is selected (curves, segments, points, handles, position, bounds, ...). And a curve is assumed selected if all of its parts are selected (points and handles).
With that in mind, you can create an algorithm to retrieve "what is really selected" based on project.getItems({selected: true}) as its first part. Then, you need to loop through curves and segments to check if they are selected.
Here is a sketch demonstrating a possible solution.
var vector = new Point(10, 10);
// Create path.
var path = new Path({
segments: [
[100, 100],
[200, 100],
[260, 170],
[360, 170],
[420, 250]
],
strokeColor: 'red',
strokeWidth: 10
});
// Translate given thing along global vector.
function translateThing(thing) {
switch (thing.getClassName()) {
case 'Path':
thing.position += vector;
break;
case 'Curve':
thing.segment1.point += vector;
thing.segment2.point += vector;
break;
case 'Segment':
thing.point += vector;
break;
}
}
// On mouse down...
function onMouseDown(event) {
// ...only select what was clicked.
path.selected = false;
hit = paper.project.hitTest(event.point);
if (hit && hit.location) {
hit.location.curve.selected = true;
}
else if (hit && hit.segment) {
hit.segment.selected = true;
}
// We check all items for demo purpose.
// Move all selected things.
// First get selected items in active layer...
project.activeLayer.getItems({ selected: true })
// ...then map them to what is really selected...
.map(getSelectedThing)
// ...then translate them.
.forEach(translateThing);
}
// This method returns what is really selected in a given item.
// Here we assume that only one thing can be selected at the same time.
// Returned thing can be either a Curve, a Segment or an Item.
function getSelectedThing(item) {
// Only check curves and segments if item is a path.
if (item.getClassName() === 'Path') {
// Check curves.
for (var i = 0, l = item.curves.length; i < l; i++) {
if (item.curves[i].selected) {
return item.curves[i];
}
}
// Check segments.
for (var i = 0, l = item.segments.length; i < l; i++) {
if (item.segments[i].selected) {
return item.segments[i];
}
}
}
// return item by default.
return item;
}
That said, depending on your real use case, your current workaround could be more appropriate than this approach.
So i have a TelerikUigrid and im trying to use serverside filtering and i have a very weird issue.
So when i filter 1 single column of the grid everything works as intended but when i filter 2 or more columns at the same time i encounter it doesn't work.
The problem happens because the my 2 filtered columns both get saved in a single object that is not loopable so in this example below if i filter 2 columns filter will have a count of 2 but is not loopable so i can't "split" the objects.
So when there is a single object in filter it works fine because there is only 1 to choose from but when there is 2 or more Visual Studio doesn't know which one it should choose so my variable remails a null.
if (request.filter != null && request.filter.Any())
{
foreach(var filter in request.filter)
{
var filterDescriptor = filter as FilterDescriptor;
if (filterDescriptor.Value != null)
{
//Code
}
}
If you have two filters then the filter comes in as an object called CompositeFilterDescriptor.
You'll need something like this:
for (var i = 0; i < filters.Count; i++)
{
if (filters[i] is CompositeFilterDescriptor)
{
var outerCompositeFilter = (CompositeFilterDescriptor)filters[i];
for (var j = 0; j < outerCompositeFilter.FilterDescriptors.Count; j++)
{
if (outerCompositeFilter.FilterDescriptors[j] is FilterDescriptor)
{
// Do something with this filter
}
}
}
if (filters[i] is FilterDescriptor)
{
// Only 1 filter - do something with it
}
}
I want to copy the style information from cells to ranges, like Format Painter in Excel. The documentation says to do something like this:
$activeSheet->duplicateStyle($activeSheet->getStyle('A1'), 'D1:D100');
$activeSheet->duplicateStyle($activeSheet->getStyle('B1'), 'E1:E100');
There appears to be a bug because both D1:D100 and E1:E100 get the style from cell B1. If I change the order of the two lines, both ranges get the style from A1. Similarly,
$styleA = $activeSheet->getStyle('A1');
$styleB = $activeSheet->getStyle('B1');
$activeSheet->duplicateStyle($styleA, 'D1:D100');
results in D1:D100 getting style info from cell B1. The last getStyle value is used in all duplicateStyle results.
I'm sure that a future release of PHPExcel will have a fix, I just need to figure out a work-around until then.
One workround for you might be to use the style xf Indexes:
$xfIndex = $activeSheet->getCell('A1')->getXfIndex();
Then to set that value for the xfIndex of all cells in the range
for ($col = 'D'; $col != 'E'; ++$col) {
for ($row = 1; $row <= 100; ++$row) {
$activeSheet->getCell($col . $row)->setXfIndex($xfIndex);
}
}
EDIT
Alternatively, apply fix to the duplicateStyle() method in Classes/PHPExcel/Worksheet.php
lines 1479 to 1486 currently read:
if ($this->_parent->cellXfExists($pCellStyle)) {
// there is already this cell Xf in our collection
$xfIndex = $pCellStyle->getIndex();
} else {
// we don't have such a cell Xf, need to add
$workbook->addCellXf($pCellStyle);
$xfIndex = $pCellStyle->getIndex();
}
change to:
if ($existingStyle = $this->_parent->getCellXfByHashCode($pCellStyle->getHashCode())) {
// there is already such cell Xf in our collection
$xfIndex = $existingStyle->getIndex();
} else {
// we don't have such a cell Xf, need to add
$workbook->addCellXf($pCellStyle);
$xfIndex = $pCellStyle->getIndex();
}
Similarly in the applyFromArray() method in Classes/PHPExcel/Style.php
lines 425 to 432 currently read:
if ($workbook->cellXfExists($newStyle)) {
// there is already such cell Xf in our collection
$newXfIndexes[$oldXfIndex] = $existingStyle->getIndex();
} else {
// we don't have such a cell Xf, need to add
$workbook->addCellXf($newStyle);
$newXfIndexes[$oldXfIndex] = $newStyle->getIndex();
}
change to:
if ($existingStyle = $workbook->getCellXfByHashCode($newStyle->getHashCode())) {
// there is already such cell Xf in our collection
$newXfIndexes[$oldXfIndex] = $existingStyle->getIndex();
} else {
// we don't have such a cell Xf, need to add
$workbook->addCellXf($newStyle);
$newXfIndexes[$oldXfIndex] = $newStyle->getIndex();
}
EDIT #2
Fix has now been pushed to the develop branch on github. It does give a slight performance hit, depending on the number of styles in use... I'll try and get a faster version tomorrow night
I use Qt and C++, I have a list (QList<int>)
list<<1<<3<<4<<5<<9<<22<<32<<45
I want to make this
If user enter 4 I want to make this;
list1<<1<<3<<4<<5
list2<<9<<22<<32<<45
If user enter 3, I want to divide 3 lists etc.. How can I do this?
See the code below. I have not tested it , but i might give you an idea. Remember to
#include <QtAlgorithms> too.
read x;
QVector<QList<QString> > vectorOfLists;
bool continueLoop = true;
while (continueLoop)
{
QList<QString> temp(x);
if (list.count () > x)
{
qCopy(list.begin(), list.begin()+x, temp.begin());
list.erase (list.begin(), list.begin()+x);
}
else
{
qCopy(list.begin(), list.end(), temp.begin());
continueLoop = false;
}
//Add list to collection
vectorOfLists.append (temp);
}