You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否通过JS提取HTML嵌入Flash游戏的分数变量并写入SQL表?

Great question! Let’s break this down clearly since this is a common pain point with legacy Flash content.

Can You Extract Score Variables from an Embedded Flash Game?

The short answer: It’s possible, but only if the Flash game was intentionally built to expose its internal data to external JavaScript. Flash runs in a sandboxed environment, so it blocks outside access to variables/methods by default.

The Critical Requirement: Flash Must Expose an External Interface

For JavaScript to access the game’s score, the Flash developer needs to use ActionScript’s ExternalInterface class to explicitly expose either the score variable itself or a method to retrieve it. If the game wasn’t built with this in mind, you’ll be stuck—sandbox security rules will prevent any direct access to internal game data.

Looking at your embed code:

<embed src="http://www.shooter-bubble.com/bubbleshooter2.swf?pn_extravars=arcade~storescore|no_html~1" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="728" height="550">

The pn_extravars parameter looks like a custom config for the game, but it doesn’t guarantee the score is exposed to JS. You’d need to check if the game has documented external APIs, or reach out to its developer for clarification.

If the Game Supports ExternalInterface: How to Extract the Score

Assuming the game exposes a method like getCurrentScore() via ExternalInterface, here’s how to pull the score with JavaScript:

  1. Add an id to your <embed> tag to target it easily:
<embed id="bubbleShooterGame" src="..." quality="high" ...>
  1. Call the exposed Flash method from your JS:
// Grab the Flash element
const flashGame = document.getElementById('bubbleShooterGame');
// Retrieve the score using the exposed method
const playerScore = flashGame.getCurrentScore();
console.log("Player's current score:", playerScore);

Important Caveats to Watch For

  • Browser Support: Modern browsers (Chrome, Firefox, Edge) no longer support Flash by default. Users would need to enable deprecated plugins or use outdated browsers, which makes this solution impractical for most use cases.
  • Cross-Domain Restrictions: If your webpage and the SWF file are hosted on different domains, Flash’s sandbox rules will block JS-SWF interactions unless the SWF’s server has a crossdomain.xml file that allows cross-origin access.
  • No Interface = No Luck: If the game doesn’t expose any external APIs, there’s no reliable way to extract the score. Workarounds like memory reading or screen OCR are complex, fragile, and likely violate the game’s terms of service.

Saving the Score to an SQL Table

Once you’ve retrieved the score, you’ll need to send it to a backend server to store it in SQL (front-end JS can’t directly write to SQL databases for security reasons):

  1. Build a simple backend endpoint (example with PHP):
<?php
// Get the score from the POST request
$score = $_POST['player_score'];

// Connect to your SQL database
$dbConn = new mysqli('localhost', 'your_username', 'your_password', 'your_database');

// Insert the score into your table
$stmt = $dbConn->prepare("INSERT INTO game_scores (score_value) VALUES (?)");
$stmt->bind_param("i", $score);
$stmt->execute();

// Clean up
$stmt->close();
$dbConn->close();

echo "Score saved successfully!";
?>
  1. Send the score from your front-end JS to this endpoint:
const playerScore = flashGame.getCurrentScore();

// Use fetch to send a POST request
fetch('/save-score.php', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
  },
  body: `player_score=${playerScore}`
})
.then(response => response.text())
.then(message => console.log(message))
.catch(error => console.error("Failed to save score:", error));

Final Note

Since Flash is effectively deprecated, your best long-term bet is to find an HTML5 version of the game if possible. HTML5 games run directly in the browser, making score extraction and storage far simpler and more reliable.

内容的提问来源于stack exchange,提问作者Bjamse

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:02:04