Could an array or two, solve this? - arrays

I took over a project and I'm really new to as3! I need to fix an unresolved problem hopefully without starting over from scratch.
I have a contaner_mc, holding four puppet_mc's (puppet_mc1, puppet_mc2, puppet_mc3, puppet_mc4) and each puppet_mc holds four buttons (buddy_bnt_1, buddy_bnt_2, buddy_bnt_3, buddy_bnt_4).
I need the listener to know what button was clicked and from what puppet that button was clicked?
Object(this).contaner_mc.puppet_mc?.buddy_bnt_?.addEventListener(MouseEvent.CLICK, fl_Click);
function fl_Click(event:MouseEvent):void
{
gotoAndPlay(15);
}
Any advice would be greatly appreciated!

Event bubbling should to the magic:
container_mc.addEventListener(MouseEvent.CLICK, click_handler);
function click_handler(event:MouseEvent):void {
if (event.currentTarget == event.target) {
return; // the container is the dispatcher
}
const sprite:Sprite = event.target as Sprite; // just for a typing
if (!sprite) {
trace("event.target is no sprite, set break point here for debugging.");
return;
}
if (sprite.name == 'buddy_bnt_1' || sprite.name == 'puppet_mc1') {
// do something
} else if (sprite.name == 'buddy_bnt_2' || sprite.name == 'puppet_mc2') {
// do something different
} else if (sprite.name == 'buddy_bnt_3' || sprite.name == 'puppet_mc3') {
// do something different
} else if (sprite.name == 'buddy_bnt_4' || sprite.name == 'puppet_mc4') {
// do something different
}
}

container_mc.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void
{
var clickedObject:DisplayObject = event.target as DisplayObject;
trace (clickedObject.name); // name of button clicked
trace (clickedObject.parent.name); // name of the parent
}
I used DisplayObject so that the code would work with a sprite , movieclip, or any DisplayObject. So make sure you import if you haven't already :
import flash.display.DisplayObject;

Related

Modern 7.0 ComboBox fires 'select' event on every value change

The combobox in modern fires the "select" event every time the input changes. This is very different from classic. With it doing this there is no way to differentiate between a user making a selection and pragmatically setting the value of the field.
This was reported as a bug in the Sencha forums:
https://www.sencha.com/forum/showthread.php?468730-Modern-6-5-2-ComboBox-fires-select-event-on-every-value-change
The link above also contains a fiddler to demonstrate the issue.
Has anyone run into this as an issue, and how did you overcome it?
forceSelection: true will help to solve this problem but will not cancel the bug in cases when forced selection is not needed
Edit:
This behavior is due to method syncValue (search in this source - method is private and hasn't documentation)
I don’t understand why the component developer chose to create a record even if it isn’t exist.
Comment from source file:
Either user has typed something (isInput), or we've had a setValue to a value which has no match in the store, and we are not forceSelection: true. We create a new record.
I propose to fix this behavior using the following override:
fiddle
Ext.define('Ext.field.SelectOverride', {
override: 'Ext.field.Select',
autoCreateRecord: false,
syncValue: function() {
var me = this,
store = me.getStore(),
forceSelection = me.getForceSelection(),
valueNotFoundText = me.getValueNotFoundText(),
is, isCleared, isInput, value, matchedRecord;
if (me.reconcilingValue || !store || !store.isLoaded() || store.hasPendingLoad()) {
return;
}
me.reconcilingValue = true;
me.getSelection(); // make sure selection config is flushed
is = {};
is[me.syncMode] = true;
value = ((isInput = is.input || is.filter)) ? me.getInputValue() : me.getValue();
isCleared = value == null || value === '';
if (!isCleared) {
if (me.getMultiSelect()) {
return me.syncMultiValues(Ext.Array.from(value));
}
matchedRecord = (isInput ? store.byText : store.byValue).get(value);
if (matchedRecord) {
if (!matchedRecord.isEntity) {
matchedRecord = matchedRecord[0];
}
}
else if (!forceSelection) {
matchedRecord = me.findRecordByValue(value);
}
}
// Either user has typed something (isInput), or we've had a setValue
// to a value which has no match in the store, and we are not forceSelection: true.
// We create a new record.
if (!isCleared && !matchedRecord && !forceSelection && me.autoCreateRecord) {
matchedRecord = me.createEnteredRecord(value);
}
else {
if (isInput || is.store) {
if (!matchedRecord && forceSelection) {
me.setValue(null);
me.setSelection(null);
if (!is.filter) {
me.setFieldDisplay();
}
}
} else {
if (isCleared) {
if (me.mustAutoSelect()) {
matchedRecord = store.first();
if (me.getAutoSelect() === 'initial') {
me.setAutoSelect(false);
}
}
else {
me.setSelection(null);
}
}
else if (!matchedRecord && valueNotFoundText) {
me.setError(valueNotFoundText);
}
}
}
if (matchedRecord) {
me.setSelection(matchedRecord);
}
me.reconcilingValue = false;
}
});

Hide and show the Toolbar according to the scrolling

This question is referring to Codename One only.
I need to make the Toolbar of a Codename One Form moving as shown in this video:
https://www.informatica-libera.net/videoLavoro/hideShowToolbarOnScrolling.mp4
As you can see, the scroll up causes the Toolbar to gradually disappear, while the scroll down causes the Toolbar to gradually reappear.
A solution like https://stackoverflow.com/a/55856590 is not applicable because I don't need to change the UIID of the Toolbar, but I need to move the Toolbar up and down during the scroll, to get the same effect shown in the video.
This is the approach we took in the whatsapp clone application for toolbar as that's the exact behavior of whatsapp. There is more to it but this block contains most of the logic that implements this:
private void bindFolding(Container titleArea, int titleHeight,
Container... scrollables) {
addPointerReleasedListener(e -> {
if(titleArea.getHeight() != titleHeight &&
titleArea.getHeight() != 0) {
if(titleHeight - titleArea.getHeight() > titleHeight / 2) {
titleArea.setPreferredSize(null);
} else {
titleArea.setPreferredH(0);
}
titleArea.getParent().animateLayout(100);
}
});
for(Container c : scrollables) {
c.addScrollListener((scrollX, scrollY, oldscrollX,
oldscrollY) -> {
// special case for tensile drag
if(scrollY <= 10) {
titleArea.setPreferredSize(null);
return;
}
int diff = oldscrollY - scrollY;
if(diff > 0) {
if(titleArea.getHeight() < titleHeight) {
titleArea.setPreferredH(Math.min(titleHeight,
titleArea.getPreferredH() + diff));
titleArea.setHeight(titleArea.getPreferredH());
titleArea.getParent().revalidate();
}
} else {
if(diff < 0) {
if(titleArea.getHeight() > 0) {
titleArea.setPreferredH(Math.max(0,
titleArea.getPreferredH() + diff));
titleArea.setHeight(titleArea.getPreferredH());
titleArea.getParent().revalidate();
}
}
}
});
}
}

jsPsych integration with React

I've been trying to put a custom experiment made with jsPsych, a library for running behavioral experiments, with custom plugins into a React container but i've run into some issues.
The first thing i tried to do was use makebrainwave's jspsych-react package, but when i try to run the example, after having to change the routes of the files in the import section and replacing the use of 'fs', i'm still running into this error:
Trial level node is missing the "type" parameter. The parameters for the node are: {} experiment.js:924
TypeError: jsPsych.plugins[trial.type] is undefined[Learn More] experiment.js:1051
Could anyone help me with it? It looks like it's trying to initialize something and failing, but otherwise I'm kinda lost in the error.
The first error occurs in the constructor function:
// constructor
var _construct = function() {
// store a link to the parent of this node
parent_node = parent;
// create the ID for this node
if (typeof parent == 'undefined') {
relative_id = 0;
} else {
relative_id = relativeID;
}
// check if there is a timeline parameter
// if there is, then this node has its own timeline
if ((typeof parameters.timeline !== 'undefined') || (typeof jsPsych.plugins[trial_type] == 'function')) {
// create timeline properties
timeline_parameters = {
timeline: [],
loop_function: parameters.loop_function,
conditional_function: parameters.conditional_function,
sample: parameters.sample,
randomize_order: typeof parameters.randomize_order == 'undefined' ? false : parameters.randomize_order,
repetitions: typeof parameters.repetitions == 'undefined' ? 1 : parameters.repetitions,
timeline_variables: typeof parameters.timeline_variables == 'undefined' ? [{}] : parameters.timeline_variables
};
self.setTimelineVariablesOrder();
// extract all of the node level data and parameters
var node_data = Object.assign({}, parameters);
delete node_data.timeline;
delete node_data.conditional_function;
delete node_data.loop_function;
delete node_data.randomize_order;
delete node_data.repetitions;
delete node_data.timeline_variables;
delete node_data.sample;
node_trial_data = node_data; // store for later...
// create a TimelineNode for each element in the timeline
for (var i = 0; i < parameters.timeline.length; i++) {
timeline_parameters.timeline.push(new TimelineNode(Object.assign({}, node_data, parameters.timeline[i]), self, i));
}
}
// if there is no timeline parameter, then this node is a trial node
else {
// check to see if a valid trial type is defined
var trial_type = parameters.type;
if (typeof trial_type == 'undefined') {
console.error('Trial level node is missing the "type" parameter. The parameters for the node are: ' + JSON.stringify(parameters));
} else if ((typeof jsPsych.plugins[trial_type] == 'undefined') && (trial_type.toString().replace(/\s/g,'') != "function(){returntimeline.timelineVariable(varname);}")) {
console.error('No plugin loaded for trials of type "' + trial_type + '"');
}
// create a deep copy of the parameters for the trial
trial_parameters = Object.assign({}, parameters);
}
}();
And the second one in the first line of the folowing function
function setDefaultValues(trial){
var trial_parameters = Object.keys(jsPsych.plugins[trial.type].info.parameters);
for(var i=0; i<trial_parameters.length; i++){
if(typeof trial[trial_parameters[i]] == 'undefined' || trial[trial_parameters[i]] === null){
if(typeof jsPsych.plugins[trial.type].info.parameters[trial_parameters[i]].default == 'undefined'){
console.error('You must specify a value for the '+trial_parameters[i]+' parameter in the '+trial.type+' plugin.');
} else {
trial[trial_parameters[i]] = jsPsych.plugins[trial.type].info.parameters[trial_parameters[i]].default;
}
}
}
}
I installed jspsych-react with yarn into the project and the test container is the following:
import React, { Component } from 'react'
import { Experiment } from "jspsych-react";
import { visualOddball } from "./examples/timelines/visualOddball";
import { callbackHTMLDisplay } from "./examples/plugins/callbackHTMLDisplay";
import { callbackImageDisplay } from "./examples/plugins/callbackImageDisplay";
export default class ExperimentComponent extends Component {
render() {
return (
<div>
<Experiment
settings={{ timeline: visualOddball }}
plugins={{
"callback-html-display": callbackHTMLDisplay,
"callback-image-display": callbackImageDisplay
}}
/>
</div>
);
}
}
Has anyone integrated something similar without using the jspsych-react package? which approach did you take?
Thanks in advance!

On/Off time(datetime field) doesn't cleared after cancel button is pressed

I open page properties and fill some fields
After I pressed cancel button, and reopened properties dialog, all field cleared, but datetime fields didn't.
What is the rigth way to clear datetime fields?
I was debuggin and find out strange behavior of isApplyDefault method in \ibs\cq\ui\widgets\source\ext\override\widgets\form\Field.js. It is compare created and modefied date, if they equals returns true, otherwise false.
I just ovveride method processRecord in DateTime.js to remove calling isApplyDefault:
processRecord: function(record, path) {
if (this.fireEvent('beforeloadcontent', this, record, path) !== false) {
var v = record.get(this.getName());
if (v == undefined && this.defaultValue != null) {
this.setValue(this.defaultValue);
}
else {
this.setValue(v);
}
this.fireEvent('loadcontent', this, record, path);
}
}
in Field.js it is:
processRecord: function(record, path) {
if (this.fireEvent('beforeloadcontent', this, record, path) !== false) {
var v = record.get(this.getName());
if (v == undefined && this.defaultValue != null) {
if (this.isApplyDefault(record, path)) {
this.setValue(this.defaultValue);
}
}
else {
this.setValue(v);
}
this.fireEvent('loadcontent', this, record, path);
}
}
See also in adobe forum

Unity unityscript Error

I have an array learnnum that looks like [0,1,1,0,1,1,1,1,0].
I need to basically ask the user for an input Left Mouse Button or Right Mouse Button. If Left, then the values of learnnum of [i] is flipped, else nothing happens. I only do this for i=1,3,5,7. I have written the below code, but it does not work properly, instead of going for all the 4 conditions... it directly goes to 4. It seems that it is not waiting for the input conditions... Is there any way I can correct this?
function changeNumba(i)
{ //check1=true;
print ("PRINTT "+check1);
while(!Input.GetButtonDown("Fire1") && !Input.GetButtonDown("Fire2"))
{
if(Input.GetButtonDown("Fire1"))
{
check1++;
}
if(Input.GetButtonDown("Fire2"))
{
learnednum[i]=0 ? 1 : 0;
check1++;
}
}
}
function changelearn()
{
//FIRST STEP
//if(check1)
if(move1==9 && check1==0)
{changeNumba(1);
}
//SECOND STEP
if(move1==9 && check1==1)
{changeNumba(3);
}
if(move1==9 && check1==2)
{changeNumba(5);
}
if(move1==9 && check1==3)
{changeNumba(7);
}
}
var check1=0;
//1,3,5,7
function Update () {
if(move1==9)//this is just a game condition. Do not bother about it.
{
changelearn();
}
}
from looking at the unity script api:
http://docs.unity3d.com/Documentation/ScriptReference/Input.GetButtonDown.html
you should not have a while() loop inside of your Update() method.
change changeNumba() as follows:
function changeNumba(i)
{
if(Input.GetButtonDown("Fire1")){
check1++;
}
if(Input.GetButtonDown("Fire2")){
learnednum[i] = learnednum[i]==0 ? 1 : 0;
check1++;
}
}

Resources